예제 #1
0
 private OperationResult AttachEmployeerIfNeeded(Profile profile)
 {
     if (profile.EmployeeId != null)
     {
         var employeeFromBdResult = employeeHandler.Get(profile.EmployeeId.Value);
         if (!employeeFromBdResult.Ok)
         {
             return(OperationResult.BuildFromOperationResult(employeeFromBdResult));
         }
         dbContext.Entry(employeeFromBdResult.ResultModel).CurrentValues.SetValues(profile.Employee);
         profile.Employee = employeeFromBdResult.ResultModel;
     }
     if (profile.Employee != null)
     {
         dbContext.Attach(profile.Employee);
     }
     return(OperationResult.BuildSuccess());
 }
예제 #2
0
        public OperationResult ChangeEmployeeWithProfile(Profile profile)
        {
            var profileFromBdResult = profileHandler.Get(profile.Id);

            if (!profileFromBdResult.Ok)
            {
                return(OperationResult.BuildFromOperationResult(profileFromBdResult));
            }
            dbContext.Entry(profileFromBdResult.ResultModel).CurrentValues.SetValues(profile);
            profileFromBdResult.ResultModel.Employee = profile.Employee;

            var attachResult = AttachEmployeerIfNeeded(profileFromBdResult.ResultModel);

            if (!attachResult.Ok)
            {
                return(attachResult);
            }

            dbContext.Update(profileFromBdResult.ResultModel);
            dbContext.SaveChanges();
            return(OperationResult.BuildSuccess());
        }