예제 #1
0
        public ActionResult Edit(Guid id)
        {
            var designation = designationService.Find(id);

            if (designation == null)
            {
                return(HttpNotFound());
            }
            return(View(designation));
        }
예제 #2
0
        public ActionResult Post(Designation vm)
        {
            Designation pt = vm;

            if (ModelState.IsValid)
            {
                if (vm.DesignationId <= 0)
                {
                    pt.CreatedDate  = DateTime.Now;
                    pt.ModifiedDate = DateTime.Now;
                    pt.CreatedBy    = User.Identity.Name;
                    pt.ModifiedBy   = User.Identity.Name;
                    pt.ObjectState  = Model.ObjectState.Added;
                    _DesignationService.Create(pt);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", vm));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId    = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Designation).DocumentTypeId,
                        DocId        = pt.DesignationId,
                        ActivityType = (int)ActivityTypeContants.Added,
                    }));

                    return(RedirectToAction("Create").Success("Data saved successfully"));
                }
                else
                {
                    List <LogTypeViewModel> LogList = new List <LogTypeViewModel>();

                    Designation temp = _DesignationService.Find(pt.DesignationId);

                    Designation ExRec = Mapper.Map <Designation>(temp);

                    temp.DesignationName = pt.DesignationName;
                    temp.IsActive        = pt.IsActive;
                    temp.ModifiedDate    = DateTime.Now;
                    temp.ModifiedBy      = User.Identity.Name;
                    temp.ObjectState     = Model.ObjectState.Modified;
                    _DesignationService.Update(temp);

                    LogList.Add(new LogTypeViewModel
                    {
                        ExObj = ExRec,
                        Obj   = temp,
                    });
                    XElement Modifications = new ModificationsCheckService().CheckChanges(LogList);

                    try
                    {
                        _unitOfWork.Save();
                    }

                    catch (Exception ex)
                    {
                        string message = _exception.HandleException(ex);
                        ModelState.AddModelError("", message);
                        return(View("Create", pt));
                    }

                    LogActivity.LogActivityDetail(LogVm.Map(new ActiivtyLogViewModel
                    {
                        DocTypeId       = new DocumentTypeService(_unitOfWork).FindByName(MasterDocTypeConstants.Designation).DocumentTypeId,
                        DocId           = temp.DesignationId,
                        ActivityType    = (int)ActivityTypeContants.Modified,
                        xEModifications = Modifications,
                    }));

                    return(RedirectToAction("Index").Success("Data saved successfully"));
                }
            }

            return(View("Create", vm));
        }