/// <summary>
 /// Gets the facility role model by identifier.
 /// </summary>
 /// <param name="facilityRoleId">The facility role identifier.</param>
 /// <returns></returns>
 public FacilityRole GetFacilityRoleModelById(int facilityRoleId)
 {
     using (var rep = UnitOfWork.FacilityRoleRepository)
     {
         var model = rep.Where(fr => !fr.IsDeleted && fr.FacilityRoleId == facilityRoleId).FirstOrDefault();
         if (model != null)
         {
             var facilityroleModel = new FacilityRoleCustomModel
             {
                 FacilityRoleId     = model.FacilityRoleId,
                 FacilityId         = model.FacilityId,
                 RoleId             = model.RoleId,
                 CorporateId        = model.CorporateId,
                 CreatedBy          = model.CreatedBy,
                 CreatedDate        = model.CreatedDate,
                 ModifiedBy         = model.ModifiedBy,
                 ModifiedDate       = model.ModifiedDate,
                 IsDeleted          = model.IsDeleted,
                 DeletedBy          = model.DeletedBy,
                 DeletedDate        = model.DeletedDate,
                 IsActive           = model.IsActive,
                 SchedulingApplied  = model.SchedulingApplied,
                 CarePlanAccessible = model.CarePlanAccessible
             };
             return(facilityroleModel);
         }
     }
     return(new FacilityRole());
 }
        /// <summary>
        /// Reset the FacilityStructure View Model and pass it to FacilityStructureAddEdit Partial View.
        /// </summary>
        /// <returns></returns>
        public ActionResult ResetFacilityRoleForm()
        {
            //Intialize the new object of FacilityStructure ViewModel
            var facilityStructureViewModel = new FacilityRoleCustomModel();

            //Pass the View Model as FacilityStructureViewModel to PartialView FacilityStructureAddEdit just to update the AddEdit partial view.
            return(PartialView(PartialViews.FacilityRoleAddEdit, facilityStructureViewModel));
        }
 public int SaveFacilityRole(FacilityRoleCustomModel vm, long userId, DateTime currentDate)
 {
     using (var rep = UnitOfWork.FacilityRoleRepository)
     {
         var model = FacilityRoleMapper.MapViewModelToModel(vm);
         vm.RoleName = string.IsNullOrEmpty(vm.RoleName) ? string.Empty : vm.RoleName;
         return(rep.SaveFacilityRole(model, vm.AddToAll, vm.RoleName, userId, currentDate));
     }
 }
 /// <summary>
 /// Adds the update facility role custom model.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns></returns>
 public ActionResult AddUpdateFacilityRoleCustomModel(FacilityRoleCustomModel model)
 {
     using (var bal = new FacilityRoleBal())
     {
         var newId   = 0;
         var isExist = bal.CheckIfExists(model.RoleId, model.FacilityId, model.CorporateId, model.FacilityRoleId);
         if (!isExist)
         {
             newId = bal.SaveFacilityRole(model, Helpers.GetLoggedInUserId(), Helpers.GetInvariantCultureDateTime());
         }
         return(Json(newId));
     }
 }
        /// <summary>
        /// Adds the update facility role custom model.
        /// </summary>
        /// <param name="vm">The model.</param>
        /// <returns></returns>
        public int AddUpdateFacilityRoleCustomModel(FacilityRoleCustomModel vm)
        {
            var newRoleId = 0;
            var frModel   = FacilityRoleMapper.MapViewModelToModel(vm);

            using (var rep = UnitOfWork.FacilityRoleRepository)
            {
                if (vm.RoleId == 0 && !string.IsNullOrEmpty(vm.RoleName))
                {
                    var rModel = new Role
                    {
                        RoleID       = vm.RoleId,
                        CorporateId  = vm.CorporateId,
                        FacilityId   = vm.FacilityId, // new column added on Nov 07 2014 by Shashank
                        IsActive     = vm.IsActive,
                        RoleName     = vm.RoleName,
                        CreatedBy    = vm.CreatedBy,
                        CreatedDate  = vm.CreatedDate,
                        ModifiedBy   = vm.ModifiedBy,
                        ModifiedDate = vm.ModifiedDate,
                        IsDeleted    = vm.IsDeleted,
                        DeletedBy    = vm.DeletedBy,
                        DeletedDate  = vm.DeletedDate,
                    };

                    using (var roleBal = new RoleBal())
                    {
                        if (!roleBal.CheckDuplicateRole(vm.RoleId, vm.RoleName))
                        {
                            newRoleId = roleBal.AddUpdateRole(rModel);
                        }
                        else
                        {
                            return(0);
                        }

                        //Add newly added role to other facilities of this corporate
                        if (vm.AddToAll)
                        {
                            var facIds = roleBal.GetFacilityIdsByCorporateId(vm.CorporateId);
                            if (facIds != null && facIds.Any())
                            {
                                facIds = facIds.Where(f => f != vm.FacilityId).ToList();
                                foreach (var facId in facIds)
                                {
                                    //Add entries in the table Role for other facilities too.
                                    var rModel1 = new Role
                                    {
                                        RoleID       = 0,
                                        CorporateId  = vm.CorporateId,
                                        FacilityId   = facId, // new column added on Nov 07 2014 by Shashank
                                        IsActive     = vm.IsActive,
                                        RoleName     = vm.RoleName,
                                        CreatedBy    = vm.CreatedBy,
                                        CreatedDate  = vm.CreatedDate,
                                        ModifiedBy   = vm.ModifiedBy,
                                        ModifiedDate = vm.ModifiedDate,
                                        IsDeleted    = vm.IsDeleted,
                                        DeletedBy    = vm.DeletedBy,
                                        DeletedDate  = vm.DeletedDate,
                                        IsGeneric    = false
                                    };

                                    var nRoleId = roleBal.AddUpdateRole(rModel1);

                                    //Add Entries in the table FacilityRole table for other facilities.
                                    frModel.FacilityId = facId;
                                    frModel.RoleId     = nRoleId;
                                    rep.Create(frModel);
                                }
                            }
                        }
                    }
                }

                frModel.FacilityId = vm.FacilityId;
                frModel.RoleId     = newRoleId > 0 ? newRoleId : vm.RoleId;

                if (vm.FacilityRoleId > 0)
                {
                    rep.UpdateEntity(frModel, frModel.FacilityRoleId);
                }
                else
                {
                    rep.Create(frModel);
                }

                return(1);
            }
        }