Ejemplo n.º 1
0
        public ActionResult Create(SpecialityViewModel specialityVM)
        {
            //     var cSpeciality = specialityRepository.CheckSpeciality(specialityVM.specialitys.SpecialityName);

            var cSpeciality = db.Specialitys.FirstOrDefault(x => x.SpecialityName == specialityVM.SpecialityName);

            try
            {
                if (ReferenceEquals(cSpeciality, null))
                {
                    if (ModelState.IsValid)
                    {
                        var newSpeciality = new Speciality();
                        if (Session["EditSpeciality"] != null)
                        {
                            newSpeciality.SpecialityID   = Convert.ToInt32(Session["EditSpeciality"]);
                            newSpeciality.SpecialityName = specialityVM.SpecialityName;
                            newSpeciality.InactiveFlag   = "N";
                            newSpeciality.ModifiedDate   = DateTime.Now;
                            specialityRepository.UpdateSpeciality(newSpeciality);
                            Session["EditSpeciality"] = null;
                        }
                        else
                        {
                            specialityRepository.InsertSpeciality(specialityVM, specialityVM.specialityss);
                        }
                        specialityRepository.Save();
                        @TempData["SuccessMessage"] = "Added Successfully....";
                    }
                }
                else
                {
                    //   ModelState.AddModelError("Speciality.SpecialityName", "Speciality Name Already Exist");
                    @TempData["Message"] = "" + specialityVM.SpecialityName + "Speciality Name Already Exist";
                }
            }
            catch (Exception)
            {
                ModelState.AddModelError(string.Empty, "Unable to Add changes. Try again, and if the problem persists contact your system administrator.");
            }
            return(RedirectToAction("Create"));
        }