/// <summary> /// For Updating Section /// </summary> /// <param name="section"></param> /// <returns></returns> public SectionAddViewModel UpdateSection(SectionAddViewModel section) { try { var sectionUpdate = this.context?.Sections.FirstOrDefault(x => x.TenantId == section.tableSections.TenantId && x.SchoolId == section.tableSections.SchoolId && x.SectionId == section.tableSections.SectionId); sectionUpdate.TenantId = section.tableSections.TenantId; sectionUpdate.SchoolId = section.tableSections.SchoolId; sectionUpdate.SectionId = section.tableSections.SectionId; sectionUpdate.Name = section.tableSections.Name; sectionUpdate.SortOrder = section.tableSections.SortOrder; section.tableSections.LastUpdated = DateTime.UtcNow; sectionUpdate.UpdatedBy = section.tableSections.UpdatedBy; this.context?.SaveChanges(); section._failure = false; return(section); } catch (Exception ex) { section.tableSections = null; section._failure = true; section._message = NORECORDFOUND; return(section); } }
public ActionResult <SectionAddViewModel> ViewSection(SectionAddViewModel section) { SectionAddViewModel sectionView = new SectionAddViewModel(); try { if (section.tableSections.SchoolId > 0) { sectionView = _sectionService.ViewSection(section); } else { sectionView._token = section._token; sectionView._tenantName = section._tenantName; sectionView._failure = true; sectionView._message = "Please enter valid scholl id"; } } catch (Exception es) { sectionView._failure = true; sectionView._message = es.Message; } return(sectionView); }
/// <summary> /// For Adding Section /// </summary> /// <param name="section"></param> /// <returns></returns> public SectionAddViewModel AddSection(SectionAddViewModel section) { int?MasterSectionId = Utility.GetMaxPK(this.context, new Func <Sections, int>(x => x.SectionId)); section.tableSections.SectionId = (int)MasterSectionId; section.tableSections.LastUpdated = DateTime.UtcNow; this.context?.Sections.Add(section.tableSections); this.context?.SaveChanges(); section._failure = false; return(section); }
/// <summary> /// Service layer For View Section /// </summary> /// <param name="section"></param> /// <returns></returns> public SectionAddViewModel ViewSection(SectionAddViewModel section) { SectionAddViewModel sectionView = new SectionAddViewModel(); if (TokenManager.CheckToken(section._tenantName, section._token)) { sectionView = this.sectionRepository.ViewSection(section); return(sectionView); } else { sectionView._failure = true; sectionView._message = TOKENINVALID; return(sectionView); } }
/// <summary> /// Service layer For Editing/Updating Section /// </summary> /// <param name="section"></param> /// <returns></returns> public SectionAddViewModel UpdateSection(SectionAddViewModel section) { SectionAddViewModel sectionUpdate = new SectionAddViewModel(); if (TokenManager.CheckToken(section._tenantName + section._userName, section._token)) { sectionUpdate = this.sectionRepository.UpdateSection(section); return(sectionUpdate); } else { sectionUpdate._failure = true; sectionUpdate._message = TOKENINVALID; return(sectionUpdate); } }
/// <summary> /// For Deleting Section /// </summary> /// <param name="section"></param> /// <returns></returns> public SectionAddViewModel DeleteSection(SectionAddViewModel section) { try { var sectionDel = this.context?.Sections.FirstOrDefault(x => x.TenantId == section.tableSections.TenantId && x.SchoolId == section.tableSections.SchoolId && x.SectionId == section.tableSections.SectionId); this.context?.Sections.Remove(sectionDel); this.context?.SaveChanges(); section._failure = false; section._message = "Section Deleted Successfully"; } catch (Exception es) { section._failure = true; section._message = es.Message; } return(section); }
/// <summary> /// For Adding Section /// </summary> /// <param name="section"></param> /// <returns></returns> public SectionAddViewModel AddSection(SectionAddViewModel section) { try { var checkSectionName = this.context?.Sections.Where(x => x.SchoolId == section.tableSections.SchoolId && x.TenantId == section.tableSections.TenantId && x.Name.ToLower() == section.tableSections.Name.ToLower()).FirstOrDefault(); if (checkSectionName != null) { section._failure = true; section._message = "Section Name Already Exists"; } else { //int? MasterSectionId = Utility.GetMaxPK(this.context, new Func<Sections, int>(x => x.SectionId)); int?MasterSectionId = 1; var SectionData = this.context?.Sections.Where(x => x.SchoolId == section.tableSections.SchoolId && x.TenantId == section.tableSections.TenantId).OrderByDescending(x => x.SectionId).FirstOrDefault(); if (SectionData != null) { MasterSectionId = SectionData.SectionId + 1; } section.tableSections.SectionId = (int)MasterSectionId; section.tableSections.LastUpdated = DateTime.UtcNow; this.context?.Sections.Add(section.tableSections); this.context?.SaveChanges(); section._failure = false; section._message = "Section Added Successfully"; } } catch (Exception es) { section._failure = true; section._message = es.Message; } return(section); }
/// <summary> /// For Section View By ID /// </summary> /// <param name="section"></param> /// <returns></returns> public SectionAddViewModel ViewSection(SectionAddViewModel section) { try { SectionAddViewModel sectionView = new SectionAddViewModel(); var sectionById = this.context?.Sections.FirstOrDefault(x => x.TenantId == section.tableSections.TenantId && x.SchoolId == section.tableSections.SchoolId && x.SectionId == section.tableSections.SectionId); if (sectionById != null) { sectionView.tableSections = sectionById; return(sectionView); } else { sectionView._failure = true; sectionView._message = NORECORDFOUND; return(sectionView); } } catch (Exception es) { throw; } }
/// <summary> /// For Updating Section /// </summary> /// <param name="section"></param> /// <returns></returns> public SectionAddViewModel UpdateSection(SectionAddViewModel section) { try { var sectionUpdate = this.context?.Sections.FirstOrDefault(x => x.TenantId == section.tableSections.TenantId && x.SchoolId == section.tableSections.SchoolId && x.SectionId == section.tableSections.SectionId); if (sectionUpdate != null) { var checkSectionName = this.context?.Sections.Where(x => x.SchoolId == section.tableSections.SchoolId && x.TenantId == section.tableSections.TenantId && x.SectionId != section.tableSections.SectionId && x.Name.ToLower() == section.tableSections.Name.ToLower()).FirstOrDefault(); if (checkSectionName != null) { section._failure = true; section._message = "Section Name Already Exists"; } else { section.tableSections.LastUpdated = DateTime.UtcNow; this.context.Entry(sectionUpdate).CurrentValues.SetValues(section.tableSections); this.context?.SaveChanges(); section._failure = false; section._message = "Section Updated Successfully"; } } else { section.tableSections = null; section._failure = true; section._message = NORECORDFOUND; } } catch (Exception ex) { section._failure = true; section._message = ex.Message; } return(section); }
/// <summary> /// Service Layer For Deleting Section /// </summary> /// <param name="section"></param> /// <returns></returns> public SectionAddViewModel DeleteSection(SectionAddViewModel section) { SectionAddViewModel sectionDelete = new SectionAddViewModel(); try { if (TokenManager.CheckToken(section._tenantName, section._token)) { sectionDelete = this.sectionRepository.DeleteSection(section); } else { sectionDelete._failure = true; sectionDelete._message = TOKENINVALID; } } catch (Exception es) { sectionDelete._failure = true; sectionDelete._message = es.Message; } return(sectionDelete); }
public async Task <JsonResult> CheckSectionIfExist(SectionAddViewModel data) { return(await checkSection(data.sect_id) ? Json(true, JsonRequestBehavior.AllowGet) : Json(false, JsonRequestBehavior.AllowGet)); }