public bool InsertCollege(CollegeDetailsModel collegeDetailsModel)
        {
            try
            {
                tblCollege entity = new tblCollege();

                entity = _unitOfWork.CollegeRepository.Get(filter: prop => prop.CollegeCode.Equals(collegeDetailsModel.CollegeCode)).FirstOrDefault();

                if (entity == null)
                {
                    Guid       collegeId  = Guid.NewGuid();
                    tblCollege newCollege = new tblCollege()
                    {
                        IsDeleted   = false,
                        CollegeID   = collegeId,
                        CollegeCode = collegeDetailsModel.CollegeCode,
                        CollegeName = collegeDetailsModel.CollegeName
                    };
                    _unitOfWork.CollegeRepository.Insert(newCollege);
                    _unitOfWork.Save();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                string currentFile = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
                ErrorLogger.LogException(e, currentFile);
                return(false);
            }
        }
 public List <CollegeDetailsModel> GetColleges()
 {
     try
     {
         IEnumerable <tblCollege>   lstColleges = _unitOfWork.CollegeRepository.Get();
         List <CollegeDetailsModel> lstModels   = new List <CollegeDetailsModel>();
         foreach (var entry in lstColleges)
         {
             CollegeDetailsModel model = new CollegeDetailsModel()
             {
                 CollegeID   = entry.CollegeID,
                 CollegeCode = entry.CollegeCode,
                 CollegeName = entry.CollegeName
             };
             if (entry.IsDeleted)
             {
                 //Don't add the college in the list
             }
             else
             {
                 lstModels.Add(model);
             }
         }
         return(lstModels);
     }
     catch (Exception e)
     {
         string currentFile = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
         ErrorLogger.LogException(e, currentFile);
         List <CollegeDetailsModel> collegesList = new List <CollegeDetailsModel>();
         return(collegesList);
     }
 }
 public CollegeDetailsModel GetCollege(Guid ID)
 {
     try
     {
         tblCollege entity = new tblCollege();
         entity = _unitOfWork.CollegeRepository.GetByID(ID);
         CollegeDetailsModel model = new CollegeDetailsModel()
         {
             CollegeID   = entity.CollegeID,
             CollegeCode = entity.CollegeCode,
             CollegeName = entity.CollegeName
         };
         if (entity.IsDeleted)
         {
             return(new CollegeDetailsModel());
         }
         else
         {
             return(model);
         }
     }
     catch (Exception e)
     {
         string currentFile = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
         ErrorLogger.LogException(e, currentFile);
         CollegeDetailsModel model = new CollegeDetailsModel();
         return(model);
     }
 }
        public ActionResult UpdateCollege(Guid id)
        {
            CollegeService      collegeService = new CollegeService();
            CollegeDetailsModel modelToDisplay = new CollegeDetailsModel();

            modelToDisplay = collegeService.GetCollege(id);
            return(View(modelToDisplay));
        }
        public ActionResult ViewCollege(Guid id)
        {
            CollegeService      collegeService = new CollegeService();
            CollegeDetailsModel modelToView    = new CollegeDetailsModel();

            modelToView = collegeService.GetCollege(id);
            return(View(modelToView));
        }
        public ActionResult UpdateCollege(CollegeDetailsModel modelToUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            CollegeService collegeService = new CollegeService();

            if (collegeService.UpdateCollege(modelToUpdate))
            {
                TempData["toast"] = "College Updated successfully";
                return(RedirectToAction("ViewColleges"));
            }
            else
            {
                ModelState.AddModelError("UpdateCollegeFailedError", "Error in updating the college. The College code should be unique");
                return(this.View());
            }
        }
        public bool UpdateCollege(CollegeDetailsModel collegeDetailsModel)
        {
            try
            {
                tblCollege entityToUpdate = new tblCollege();
                entityToUpdate = _unitOfWork.CollegeRepository.GetByID(collegeDetailsModel.CollegeID);
                if (entityToUpdate == null)
                {
                    return(false);
                }

                List <tblCollege> getAllCollegeCodes = _unitOfWork.CollegeRepository.Get().ToList();
                foreach (var entry in getAllCollegeCodes)
                {
                    //CollegeCode already exists
                    if (entry.CollegeCode == entityToUpdate.CollegeCode)
                    {
                        break;
                    }
                    if (entry.CollegeCode == collegeDetailsModel.CollegeCode)
                    {
                        return(false);
                    }
                }

                entityToUpdate.CollegeCode = collegeDetailsModel.CollegeCode;
                entityToUpdate.CollegeName = collegeDetailsModel.CollegeName;

                _unitOfWork.CollegeRepository.Update(entityToUpdate);
                _unitOfWork.Save();
                return(true);
            }
            catch (Exception e)
            {
                string currentFile = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();
                ErrorLogger.LogException(e, currentFile);
                return(false);
            }
        }
        public ActionResult AddCollege()
        {
            CollegeDetailsModel modelEmpty = new CollegeDetailsModel();

            return(View());
        }