예제 #1
0
        public ActionResult Entry(TrainerCreateVm entity)
        {
            HttpPostedFileBase file = Request.Files["uploadImage"];

            if (file != null)
            {
                entity.Image = ConvertToBytes(file);
                if (ModelState.IsValid)
                {
                    var trainer  = Mapper.Map <Trainer>(entity);
                    var trainers = _trainerManager.GetAllTrainers();
                    if (trainers.FirstOrDefault(x => x.Code == trainer.Code) != null)
                    {
                        ViewBag.Message = "Exist";
                        entity.OrganizationSelectListItems = GetAllOrganizationSlItems();
                        entity.CourseSelectListItems       = GetAllCourseSlItems();
                        entity.BatchSelectListItems        = GetAllBatchSlItems();
                        return(View(entity));
                    }
                    else
                    {
                        bool isAdded = _trainerManager.Add(trainer);
                        if (isAdded)
                        {
                            ModelState.Clear();
                            ViewBag.Message = "Saved";
                            var model = new TrainerCreateVm()
                            {
                                OrganizationSelectListItems = GetAllOrganizationSlItems(),
                                CourseSelectListItems       = GetAllCourseSlItems(),
                                BatchSelectListItems        = GetAllBatchSlItems()
                            };
                            return(View(model));
                        }
                    }
                }
            }
            ModelState.AddModelError("", "An Unknown Error Occured!");
            entity.OrganizationSelectListItems = GetAllOrganizationSlItems();
            entity.CourseSelectListItems       = GetAllCourseSlItems();
            entity.BatchSelectListItems        = GetAllBatchSlItems();
            return(View(entity));
        }