예제 #1
0
        //Create Common Model With Common Lists
        RelationTypeViewModel RelIndexModel(RelationTypeViewModel model = null)
        {
            if (model == null)
            {
                model = new RelationTypeViewModel()
                {
                };
            }

            model.ListRelationType = _unitOfWork.RelationTypeRepository.GetAll().ToList();

            return(model);
        }
예제 #2
0
        public ActionResult AddRelationType(RelationTypeViewModel model)
        {
            model = RelIndexModel(model);

            try
            {
                var existObj = _unitOfWork.RelationTypeRepository.GetAll(x => x.RelationType1.ToUpper() == model.RelType.ToUpper()).FirstOrDefault();

                if (existObj != null) // Validate relation type as unique
                {
                    ModelState.AddModelError("RelType", "This Relation type is already exist");
                }

                if (ModelState.IsValid)
                {
                    RelationType relType = new RelationType()
                    {
                        RelationType1 = model.RelType
                    };

                    _unitOfWork.RelationTypeRepository.Insert(relType);

                    if (_unitOfWork.Save() > 0)
                    {
                        TempData[MessaageEnum.message.ToString()] = Messages._sucess;
                        return(RedirectToAction("RelIndex"));
                    }
                    else
                    {
                        TempData[MessaageEnum.message.ToString()] = Messages._failed;
                        return(View("RelIndex", model));
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(View("RelIndex", model));
        }