Beispiel #1
0
        public async Task <ServiceResponse <object> > EditSection(int id, SectionDtoForEdit section)
        {
            Section checkExist = _context.Sections.FirstOrDefault(s => s.SectionName.ToLower() == section.SectionName.ToLower() && s.SchoolBranchId == _LoggedIn_BranchID);

            if (checkExist != null && checkExist.Id != section.Id)
            {
                _serviceResponse.Success = false;
                _serviceResponse.Message = CustomMessage.RecordAlreadyExist;
                return(_serviceResponse);
            }
            Section dbObj = _context.Sections.FirstOrDefault(s => s.Id.Equals(section.Id));

            if (dbObj != null)
            {
                if (dbObj.Active == true && section.Active == false)
                {
                    var Sections = _context.ClassSections.Where(m => m.SectionId == dbObj.Id && m.Active == true).ToList().Count();
                    if (Sections > 0)
                    {
                        _serviceResponse.Success = false;
                        _serviceResponse.Message = string.Format(CustomMessage.RecordRelationExist, "Section");
                        return(_serviceResponse);
                    }
                }
                dbObj.SectionName = section.SectionName;
                dbObj.Active      = section.Active;
                _context.Sections.Update(dbObj);
                await _context.SaveChangesAsync();
            }
            _serviceResponse.Success = true;
            _serviceResponse.Message = CustomMessage.Updated;
            return(_serviceResponse);
        }
        public async Task <IActionResult> Put(int id, SectionDtoForEdit section)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            _response = await _repo.EditSection(id, section);

            return(Ok(_response));
        }