Exemplo n.º 1
0
        public JsonModel CreateUpdateStaff(StaffsDTO staff, TokenModel token)
        {
            using (var transaction = _context.Database.BeginTransaction())
            {
                token.OrganizationID = 2;
                token.UserID         = 1;

                JsonModel response = new JsonModel();
                //encrypt password
                if (!string.IsNullOrEmpty(staff.Password))
                {
                    staff.Password = CommonMethods.Encrypt(staff.Password);
                }
                //
                if (staff.Id == 0)
                {
                    User staffDB = iUserRepository.Get(m => (m.UserName == staff.UserName) && m.OrganizationID == token.OrganizationID);
                    if (staffDB != null) //if user try to enter duplicate records
                    {
                        response = new JsonModel(new object(), StatusMessage.StaffAlreadyExist, (int)HttpStatusCodes.UnprocessedEntity);
                    }
                    else // insert new staff
                    {
                        // insert Credentials in User table
                        User   requestUser  = SaveUser(staff, token);
                        Staffs staffsEntity = _mapper.Map <Staffs>(staff);
                        staffsEntity.CreatedBy      = token.UserID;
                        staffsEntity.UserID         = requestUser.Id;
                        staffsEntity.OrganizationID = token.OrganizationID;
                        staffsEntity.CreatedDate    = DateTime.UtcNow;
                        staffsEntity.IsActive       = true;
                        // save data in staff table
                        iStaffRepository.Create(staffsEntity);
                        iStaffRepository.SaveChanges();
                        response = new JsonModel(staffsEntity, StatusMessage.StaffCreated, (int)HttpStatusCodes.OK);
                    }
                }
                // update Staff Info
                else
                {
                    Staffs staffDB = iStaffRepository.GetFirstOrDefault(a => a.Id == staff.Id);
                    if (staffDB != null)
                    {
                        // Update info in User Table
                        User user = iUserRepository.GetFirstOrDefault(a => a.Id == staffDB.UserID);
                        user.UserName    = staff.UserName;
                        user.Password    = staff.Password;
                        user.UpdatedDate = DateTime.UtcNow;
                        user.UpdatedBy   = token.UserID;
                        iUserRepository.Update(user);
                        iUserRepository.SaveChanges();
                        //staffDB = _mapper.Map<Staffs>(staff);
                        Staffs updatedstaff = UpadteStaff(staffDB, staff, token);
                        response = new JsonModel(updatedstaff, StatusMessage.StaffUpdated, (int)HttpStatusCodes.OK);
                    }
                }
                transaction.Commit();
                return(response);
            }
        }
Exemplo n.º 2
0
 private Staffs UpadteStaff(Staffs staffDB, StaffsDTO staff, TokenModel token)
 {
     //Update Staff Info
     staffDB.FirstName           = staff.FirstName;
     staffDB.LastName            = staff.LastName;
     staffDB.MiddleName          = staff.MiddleName;
     staffDB.Address             = staff.Address;
     staffDB.CountryID           = staff.CountryID;
     staffDB.City                = staff.City;
     staffDB.StateID             = staff.StateID;
     staffDB.Zip                 = staff.Zip;
     staffDB.Latitude            = staff.Latitude;
     staffDB.Longitude           = staff.Longitude;
     staffDB.PhoneNumber         = staff.PhoneNumber;
     staffDB.NPINumber           = staff.NPINumber;
     staffDB.TaxId               = staff.TaxId;
     staffDB.DOB                 = staff.DOB;
     staffDB.DOJ                 = staff.DOJ;
     staffDB.RoleID              = staff.RoleID;
     staffDB.Email               = staff.Email;
     staffDB.ApartmentNumber     = staff.ApartmentNumber;
     staffDB.CAQHID              = staff.CAQHID;
     staffDB.Language            = staff.Language;
     staffDB.DegreeID            = staff.DegreeID;
     staffDB.EmployeeID          = staff.EmployeeID;
     staffDB.PayRate             = staff.PayRate;
     staffDB.PayrollGroupID      = staff.PayrollGroupID;
     staffDB.IsRenderingProvider = staff.IsRenderingProvider;
     staffDB.AboutMe             = staff.AboutMe;
     staffDB.UpdatedBy           = token.UserID;
     staffDB.UpdatedDate         = DateTime.UtcNow;
     iStaffRepository.Update(staffDB);
     iStaffRepository.SaveChanges();
     return(staffDB);
 }
Exemplo n.º 3
0
 public JsonModel GetStaff(int?id, TokenModel token)
 {
     token.OrganizationID = 2;
     // get staff info
     if (id == null)
     {
         List <StaffsDTO> staffModels = iStaffRepository.GetStaff <StaffsDTO>(token).ToList();
         return(new JsonModel(staffModels, StatusMessage.FetchMessage, (int)HttpStatusCodes.OK));
     }
     else
     {
         Staffs staffs = iStaffRepository.GetFirstOrDefault(a => a.Id == id && a.IsActive == true && a.IsDeleted == false);
         if (staffs != null)
         {
             // get user info by staffid
             User user = iUserRepository
                         .GetFirstOrDefault(a => a.Id == staffs.UserID && a.IsActive == true && a.IsDeleted == false);
             StaffsDTO staffDTO = _mapper.Map <StaffsDTO>(staffs);
             if (!string.IsNullOrEmpty(user.UserName))
             {
                 staffDTO.UserName = user.UserName;
             }
             // decrypt password
             if (!string.IsNullOrEmpty(user.Password))
             {
                 staffDTO.Password = CommonMethods.Decrypt(user.Password);
             }
             return(new JsonModel(staffDTO, StatusMessage.FetchMessage, (int)HttpStatusCodes.OK));
         }
         else
         {
             return(new JsonModel(new object(), StatusMessage.NotFound, (int)HttpStatusCodes.NotFound));
         }
     }
 }
Exemplo n.º 4
0
        private User SaveUser(StaffsDTO entity, TokenModel token)
        {
            // ENTRY IN User table
            User requestUser = new User();

            requestUser.UserName       = entity.UserName;
            requestUser.Password       = entity.Password;
            requestUser.IsActive       = true;
            requestUser.IsDeleted      = false;
            requestUser.OrganizationID = token.OrganizationID;
            requestUser.CreatedBy      = token.UserID;
            requestUser.CreatedDate    = DateTime.UtcNow;
            iUserRepository.Create(requestUser);
            iUserRepository.SaveChanges();
            return(requestUser);
        }
 public ActionResult CreateUpdateStaff(StaffsDTO staffsDTO)
 {
     return(Ok(_staffService.CreateUpdateStaff(staffsDTO, GetToken(HttpContext))));
 }