Esempio n. 1
0
        //Create Common Model With Common Lists
        RelationTypeCountViewModel RelTypeModel(RelationTypeCountViewModel model = null)
        {
            if (model == null)
            {
                model = new RelationTypeCountViewModel();
            }

            model.ListEmployee          = _unitOfWork.EmployeeRepository.GetAll().ToList();
            model.ListRelationType      = _unitOfWork.RelationTypeRepository.GetAll().ToList();
            model.ListRelationTypeCount = _unitOfWork.RelationTypeCountRepository.GetAll().OrderBy(x => x.Employee.EmpName).ToList();

            return(model);
        }
Esempio n. 2
0
        public ActionResult AddRelationCount(RelationTypeCountViewModel model)
        {
            model = RelTypeModel(model);

            try
            {
                if (ModelState.IsValid)
                {
                    var existObj = _unitOfWork.RelationTypeCountRepository.GetAll(x => x.EmpId == model.EmpId && x.RelTypeId == model.RelTypeId).FirstOrDefault();

                    if (existObj == null) //Insert
                    {
                        RelationTypeCount count = new RelationTypeCount()
                        {
                            EmpId     = model.EmpId,
                            RelTypeId = model.RelTypeId,
                            MaxCount  = model.MaxCount
                        };

                        _unitOfWork.RelationTypeCountRepository.Insert(count);
                    }
                    else // Update
                    {
                        existObj.MaxCount = model.MaxCount;
                    }

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

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