Ejemplo n.º 1
0
 public ResponseModel SaveUserWeekDayOff(UserWeekDayOff model)
 {
     try
     {
         DbContext.UserWeekDayOff.Add(model);
         return(new ResponseModel {
             Success = true, Message = "Success"
         });
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 2
0
        public ResponseModel EditProfile(UserCredientialViewModel model, List <UserWeekDayOff> userWeekDayOffs)
        {
            var flag = false;

            try
            {
                UserCredentials userCredentials = DbContext.UserCredentials.Where(r => r.Id == model.Id).FirstOrDefault();
                userCredentials.FullName    = model.FullName;
                userCredentials.Email       = model.Email;
                userCredentials.IsActive    = model.IsActive;
                userCredentials.PhoneNumber = model.PhoneNumber;
                userCredentials.ImagePath   = model.ImagePath;
                userCredentials.FileId      = model.FileId;
                userCredentials.FileName    = model.FileName;
                userCredentials.UpdatedDate = DateTime.Now;

                UserCredientialDetail userCredientialDetail = DbContext.UserCredientialDetail.Where(r => r.UserCredentialId == model.Id).FirstOrDefault();
                userCredientialDetail.UserCredentialId = userCredentials.Id;
                userCredientialDetail.Gender           = model.Gender;
                userCredientialDetail.Age                       = CommonHelper.CalculateYourAge(model.DathOfBirth).Years;
                userCredientialDetail.DathOfBirth               = model.DathOfBirth;
                userCredientialDetail.BloodGroup                = model.BloodGroup;
                userCredientialDetail.Weight                    = model.Weight;
                userCredientialDetail.Height                    = model.Height;
                userCredientialDetail.Diabetes                  = model.Diabetes;
                userCredientialDetail.Allergy                   = model.Allergy;
                userCredientialDetail.AllergyDetail             = model.AllergyDetail;
                userCredientialDetail.BP                        = model.BP;
                userCredientialDetail.NationalId                = model.NationalId;
                userCredientialDetail.CompanyId                 = model.CompanyId;
                userCredientialDetail.CompanyName               = model.CompanyName;
                userCredientialDetail.CompanyAddress            = model.Address;
                userCredientialDetail.Address                   = model.Address;
                userCredientialDetail.Department                = model.Department;
                userCredientialDetail.Section                   = model.Section;
                userCredientialDetail.Designation               = model.Designation;
                userCredientialDetail.ReferencePersonName       = model.ReferencePersonName;
                userCredientialDetail.ReferencePersonCellNumber = model.ReferencePersonCellNumber;
                userCredientialDetail.ReplacementMenu           = model.ReplacementMenu;
                userCredientialDetail.SpecialMenu               = model.SpecialMenu;
                userCredientialDetail.WeekDayOff                = model.WeekDayOff;
                userCredientialDetail.LunchReceiveAddress       = model.LunchReceiveAddress;
                userCredientialDetail.UpdatedDate               = DateTime.Now;

                UserActiveStatus userActiveStatus = DbContext.UserActiveStatus.Where(r => r.UserCredentialId == userCredentials.Id).OrderByDescending(a => a.CreatedDate).FirstOrDefault();
                DbContext.Database.BeginTransaction();
                flag = true;
                DbContext.Entry(userCredentials).State = System.Data.Entity.EntityState.Modified;
                DbContext.SaveChanges();
                DbContext.Entry(userCredientialDetail).State = System.Data.Entity.EntityState.Modified;
                DbContext.SaveChanges();
                if (userWeekDayOffs != null)
                {
                    foreach (var item in userWeekDayOffs)
                    {
                        if (item.Id == null)
                        {
                            item.Id          = Guid.NewGuid().ToString();
                            item.UserId      = userCredentials.Id;
                            item.CreatedDate = DateTime.Now;
                            SaveUserWeekDayOff(item);
                        }
                        else
                        {
                            UserWeekDayOff uw = DbContext.UserWeekDayOff.Where(r => r.Id == item.Id).FirstOrDefault();
                            uw.UpdatedDate            = DateTime.Now;
                            DbContext.Entry(uw).State = System.Data.Entity.EntityState.Modified;
                        }
                    }
                }
                DbContext.SaveChanges();
                flag = false;
                DbContext.Database.CurrentTransaction.Commit();
                return(new ResponseModel {
                    Success = true, Message = "Success"
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (flag)
                {
                    DbContext.Database.CurrentTransaction.Rollback();
                }
            }
        }