TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Praveen Kumar
NA
235
22.5k
How to avoid entry of duplicate attribute?
May 29 2020 4:49 AM
Do not allow entry of duplicate attribute value for individual attribute (user code)
public
UserCode UpdateUserDefinedField(UserCode userCode, User user)
{
var dbCode = DbContext.UserCodes.Find(userCode.Id);
dbCode.Name = userCode.Name;
dbCode.Description = userCode.Description;
if
(dbCode.UserCodeTypeId != userCode.UserCodeTypeId)
if
(dbCode.UserCodeValidValues.Any(x=>x.UserCodeValues.Any()))
throw
new
NotSupportedException(
"You cannot change the attribute type because it has values in use."
);
dbCode.UserCodeTypeId = userCode.UserCodeTypeId;
dbCode.IsFreeformTextValue = userCode.IsFreeformTextValue;
dbCode.IsMandatory = userCode.IsMandatory;
// Need to handle unique constraint violation
foreach
(UserCodeValidValue ucvv
in
userCode.UserCodeValidValues)
{
UserCodeValidValue compare = dbCode.UserCodeValidValues.Where(x => x.Id == ucvv.Id).FirstOrDefault();
if
(compare !=
null
)
{
if
(ucvv.Description != compare.Description || ucvv.CodeValue != compare.CodeValue)
{
compare.CodeValue = ucvv.CodeValue;
compare.Description = ucvv.Description;
UpdateWithUser(compare, user.UserId,
"UpdateUserDefinedField"
);
}
}
else
{
ucvv.UserCode = dbCode;
AddWithUser(ucvv, user.UserId,
"UpdateUserDefinedField"
);
}
}
UpdateWithUser(dbCode, user.UserId,
"UpdateUserDefinedField"
);
return
dbCode;
}
Reply
Answers (
8
)
I want to insert selected image into database
How to use multiple sumbit buttons