/// <summary>
        /// Delete
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeActivateClass(int id)
        {
            bool isDelete = false;

            try
            {
                GEEDbContext objGEEDbContext = new GEEDbContext();
                var          UserData        = objGEEDbContext.ClassMasters.Where(a => a.ClassMaster_ID == id).FirstOrDefault();
                UserData.IsDeleted = true;
                objGEEDbContext.Entry(UserData).State = System.Data.Entity.EntityState.Modified;
                //objGEEDbContext.Entry(UserData).Property(x => x.CUserId).IsModified = false;
                if (objGEEDbContext.SaveChanges() > 0)
                {
                    isDelete = true;
                }
            }
            catch (Exception)
            {
                isDelete = false;
            }
            return(isDelete);
        }
Exemple #2
0
        public async Task <RoomModel> UpdateAsync(RoomModel entity)
        {
            ///Updated by jiya 10--Aug-2019
            ///Cause: Code breaking while data not available.
            GEEDbContext objGEEDbContext = new GEEDbContext();
            var          roomMaster      = objGEEDbContext.RoomMasters.Where(a => a.RoomMaster_ID == entity.RoomMaster_ID).FirstOrDefault();

            roomMaster.Building_ID     = entity.Building_ID;
            roomMaster.Modifiedby_ID   = Convert.ToInt32(entity.ModifiedBy_ID);
            roomMaster.ModifiedDate    = DateTime.Now;
            roomMaster.Name            = entity.Name;
            roomMaster.Code            = entity.Code;
            roomMaster.SeatingCapicity = entity.SeatingCapicity;
            roomMaster.Remarks         = entity.Remarks;
            roomMaster.GeoCoordinates  = entity.GeoCoordinates;
            objGEEDbContext.Entry(roomMaster).State = System.Data.Entity.EntityState.Modified;
            int x = await objGEEDbContext.SaveChangesAsync();

            return(new RoomModel {
                RoomMaster_ID = roomMaster.RoomMaster_ID
            });
        }
        /// <summary>
        /// This method is used to save the data for user group permission.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Save(PermissionParentModel entity)
        {
            int          isSave          = 0;
            GEEDbContext objGEEDbContext = new GEEDbContext();

            int menuid = 0;

            foreach (var item in entity.PermissionChildModelList)
            {
                Navmenu_asprole_permisison_UserGroup_mapping objPermission = new Navmenu_asprole_permisison_UserGroup_mapping();
                var _pMapping = objGEEDbContext.Navmenu_asprole_permisison_UserGroup_mapping.Where(a => a.Navrolepermisisonmapping_ID == item.Navrolepermisisonmapping_ID && a.UserGroup_ID == entity.Group_Id).SingleOrDefault();
                if (_pMapping != null)
                {
                    bool isPermisssion = item.IsPermission == 1 ? false : true;
                    if (_pMapping.ISDeleted != isPermisssion)
                    {
                        _pMapping.ISDeleted     = item.IsPermission == 1 ? false : true;
                        _pMapping.AcitiveEdit   = true;//This flag is for user role maaping procedure.
                        _pMapping.ModifiedBy_ID = entity.CreatedBy_ID;
                        entity.ModifiedDate     = DateTime.Now;
                        objGEEDbContext.Entry(_pMapping).State = System.Data.Entity.EntityState.Modified;
                        isSave = objGEEDbContext.SaveChanges();
                    }
                }
                else
                {
                    objPermission.Navrolepermisisonmapping_ID = item.Navrolepermisisonmapping_ID;
                    objPermission.SchoolID     = entity.SchoolID;
                    objPermission.CreatedDate  = DateTime.Now;
                    objPermission.ISDeleted    = item.IsPermission == 1 ? false : true;
                    objPermission.UserGroup_ID = entity.Group_Id;
                    objPermission.CreatedBy_ID = entity.CreatedBy_ID;
                    objPermission.AcitiveEdit  = true;//This flag is for user role maaping procedure.
                    objGEEDbContext.Navmenu_asprole_permisison_UserGroup_mapping.Add(objPermission);
                    isSave = objGEEDbContext.SaveChanges();
                }
                if (menuid != item.NavigationMenu_Id)
                {
                    menuid = item.NavigationMenu_Id;
                    var data = entity.PermissionChildModelList.Where(a => a.NavigationMenu_Id == menuid & a.IsPermission == 1).ToList();
                    UserGroupNavigationMenuMapping objUserGroupNavigationMenuMapping = new UserGroupNavigationMenuMapping();
                    var checkDataExists = objGEEDbContext.UserGroupNavigationMenuMappings.Where(a => a.NavigationMenuId == menuid && a.UserGroupId == entity.Group_Id).SingleOrDefault();

                    if (checkDataExists != null)
                    {
                        checkDataExists.UserGroupId      = entity.Group_Id;
                        checkDataExists.NavigationMenuId = menuid;
                        checkDataExists.SchoolID         = entity.SchoolID;
                        checkDataExists.GroupID          = entity.GroupID;
                        if (data.Count > 0)
                        {
                            checkDataExists.ISDeleted = false;
                        }
                        else
                        {
                            checkDataExists.ISDeleted = true;
                        }

                        checkDataExists.ModifiedBy_ID = entity.CreatedBy_ID;
                        checkDataExists.ModifiedDate  = DateTime.Now;
                        objGEEDbContext.Entry(checkDataExists).State = System.Data.Entity.EntityState.Modified;
                        isSave = objGEEDbContext.SaveChanges();
                    }
                    else
                    {
                        if (data.Count > 0)
                        {
                            objUserGroupNavigationMenuMapping.UserGroupId      = entity.Group_Id;
                            objUserGroupNavigationMenuMapping.NavigationMenuId = menuid;
                            objUserGroupNavigationMenuMapping.SchoolID         = entity.SchoolID;
                            objUserGroupNavigationMenuMapping.GroupID          = entity.GroupID;
                            objUserGroupNavigationMenuMapping.CreatedBy_ID     = entity.CreatedBy_ID;
                            objUserGroupNavigationMenuMapping.CreatedDate      = DateTime.Now;
                            objGEEDbContext.UserGroupNavigationMenuMappings.Add(objUserGroupNavigationMenuMapping);
                            isSave = objGEEDbContext.SaveChanges();
                        }
                    }
                }
            }
            using (GEEDbContext context = new GEEDbContext())
            {
                byte ActionID = 1;
                var  UId      = new SqlParameter("@CUserId", entity.CreatedBy_ID);
                var  MId      = new SqlParameter("@Action", ActionID);
                context.Database.ExecuteSqlCommand("RoleMappingToAspNetUserRole @CUserId, @Action", UId, MId);
            }


            return(isSave);
        }