public bool Add(Award entity, out string errorMessage) { if (entity == null) { throw new ArgumentNullException(); } string title = entity.Title; if (string.IsNullOrEmpty(title) || !char.IsLetterOrDigit(title[0])) { errorMessage = "Award title is empty or do not starts with letter or digit."; return(false); } if (title.Length > 200) { errorMessage = "Lenth of award title is more than 200."; return(false); } var id = Guid.NewGuid(); try { return(dao.Add(id, entity, out errorMessage)); } catch (Exception ex) { WriteToLog(ex); errorMessage = "Sorry. Error in data access layer. Сontact the developer."; return(false); } }
public bool Add(User entity, out string errorMessage) { if (entity == null) { throw new ArgumentNullException(); } string name = entity.Name; if (string.IsNullOrEmpty(name) || !char.IsLetterOrDigit(name[0])) { errorMessage = "User name is empty or do not starts with letter or digit."; return(false); } if (name.Length > 100) { errorMessage = "Lenth of user name is more than 100."; return(false); } if (entity.DateOfBirth > DateTime.Now || entity.DateOfBirth.Date < DateTime.Now.AddYears(-100)) { errorMessage = "User's date of birth out of range (age had to be from 0 to 100)."; return(false); } var id = Guid.NewGuid(); try { return(dao.Add(id, entity, out errorMessage)); } catch (Exception ex) { WriteToLog(ex); errorMessage = "Sorry. Error in data access layer. Сontact the developer."; return(false); } }
public bool Add(LinkUserAward entity, out string errorMessage) { if (entity == null) { throw new ArgumentNullException(); } Guid id = entity.UserId; if (id == null || id == Guid.Empty) { errorMessage = "User ID is null null empty."; return(false); } IEnumerable <KeyValuePair <Guid, User> > leftResult; try { if (!leftDao.GetById(id, out leftResult, out errorMessage)) { errorMessage = "Sorry. Error in data access layer. Сontact the developer."; return(false); } } catch (Exception ex) { WriteToLog(ex); errorMessage = "Sorry. Error in data access layer. Сontact the developer."; return(false); } if (leftResult.Count() == 0) { errorMessage = "Тhere is no User with this ID."; return(false); } id = entity.AwardId; if (id == null || id == Guid.Empty) { errorMessage = "Award ID is null null empty."; return(false); } IEnumerable <KeyValuePair <Guid, Award> > rightResult; try { if (!rightDao.GetById(id, out rightResult, out errorMessage)) { errorMessage = "Sorry. Error in data access layer. Сontact the developer."; return(false); } } catch (Exception ex) { WriteToLog(ex); errorMessage = "Sorry. Error in data access layer. Сontact the developer."; return(false); } if (rightResult.Count() == 0) { errorMessage = "Тhere is no Award with this ID."; return(false); } id = Guid.NewGuid(); try { return(linkDao.Add(id, entity, out errorMessage)); } catch (Exception ex) { WriteToLog(ex); errorMessage = "Sorry. Error in data access layer. Сontact the developer."; return(false); } }