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);
            }
        }
예제 #2
0
 public void GetByIdShouldReturnNull()
 {
     AddObjects(5);
     Assert.IsNull(dao.GetById(-1));
 }