コード例 #1
0
        private List <Error> SaveGrid1(WfRoleWfVM grid1, IEnumerable <KeyValuePair <string, ModelState> > state, RequestWf Request)
        {
            List <Error> errors = new List <Error>();

            // Deleted
            if (grid1.deleted != null)
            {
                foreach (WfRoleViewModel model in grid1.deleted)
                {
                    var wfrole = new WfRole {
                        Id = model.Id
                    };
                    _hrUnitOfWork.LeaveRepository.Remove(wfrole);
                }
            }

            if (ServerValidationEnabled)
            {
                var modified = Models.Utils.GetModifiedRows(state.Where(a => !a.Key.Contains("deleted")));
                if (modified.Count > 0)
                {
                    errors = _hrUnitOfWork.CompanyRepository.Check(new CheckParm
                    {
                        CompanyId  = CompanyId,
                        ObjectName = "WfRole",
                        Columns    = Models.Utils.GetModifiedRows(state.Where(a => !a.Key.Contains("deleted"))),
                        Culture    = Language
                    });

                    if (errors.Count() > 0)
                    {
                        return(errors);
                    }
                }
            }

            // updated records
            if (grid1.updated != null)
            {
                foreach (WfRoleViewModel model in grid1.updated)
                {
                    var wfrole = new WfRole();
                    AutoMapper(new Models.AutoMapperParm {
                        Destination = wfrole, Source = model, Transtype = TransType.Update
                    });
                    wfrole.ModifiedTime = DateTime.Now;
                    wfrole.ModifiedUser = UserName;
                    _hrUnitOfWork.LeaveRepository.Attach(wfrole);
                    _hrUnitOfWork.LeaveRepository.Entry(wfrole).State = EntityState.Modified;
                }
            }

            // inserted records
            if (grid1.inserted != null)
            {
                foreach (WfRoleViewModel model in grid1.inserted)
                {
                    var wfrole = new WfRole();
                    AutoMapper(new Models.AutoMapperParm {
                        Destination = wfrole, Source = model, Transtype = TransType.Insert
                    });
                    wfrole.WorkFlow    = Request;
                    wfrole.CreatedTime = DateTime.Now;
                    wfrole.CreatedUser = UserName;
                    _hrUnitOfWork.LeaveRepository.Add(wfrole);
                }
            }

            return(errors);
        }
コード例 #2
0
        public ActionResult RequestDetails(RequestWfFormViewModel model, OptionsViewModel moreInfo, WfRoleWfVM grid1)
        {
            List <Error> errors = new List <Error>();

            if (ModelState.IsValid)
            {
                if (ServerValidationEnabled)
                {
                    errors = _hrUnitOfWork.SiteRepository.CheckForm(new CheckParm
                    {
                        CompanyId  = CompanyId,
                        ObjectName = "RequestWfs",
                        TableName  = "RequestWf",
                        Columns    = Models.Utils.GetColumnViews(ModelState.Where(a => !a.Key.Contains('.'))),
                        Culture    = Language
                    });

                    if (errors.Count() > 0)
                    {
                        foreach (var e in errors)
                        {
                            foreach (var errorMsg in e.errors)
                            {
                                ModelState.AddModelError(errorMsg.field, errorMsg.message);
                            }
                        }

                        return(Json(Models.Utils.ParseFormErrors(ModelState)));
                    }
                }

                RequestWf record;
                //insert
                if (model.Id == 0)
                {
                    record = new RequestWf();
                    AutoMapper(new Models.AutoMapperParm
                    {
                        Destination = record,
                        Source      = model,
                        ObjectName  = "RequestWfs",
                        Options     = moreInfo,
                        Transtype   = TransType.Insert
                    });

                    record.CreatedUser = UserName;
                    record.CreatedTime = DateTime.Now;
                    if (model.HeirType != 3)
                    {
                        record.Hierarchy = null;
                    }

                    _hrUnitOfWork.LeaveRepository.Add(record);
                }
                //update
                else
                {
                    record = _hrUnitOfWork.Repository <RequestWf>().FirstOrDefault(a => a.Id == model.Id);
                    AutoMapper(new Models.AutoMapperParm
                    {
                        Destination = record,
                        Source      = model,
                        ObjectName  = "RequestWfs",
                        Version     = 0,
                        Options     = moreInfo,
                        Transtype   = TransType.Update
                    });
                    record.ModifiedTime = DateTime.Now;
                    record.ModifiedUser = UserName;
                    if (model.HeirType != 3)
                    {
                        record.Hierarchy = null;
                    }
                    _hrUnitOfWork.LeaveRepository.Attach(record);
                    _hrUnitOfWork.LeaveRepository.Entry(record).State = EntityState.Modified;
                }

                errors = SaveGrid1(grid1, ModelState.Where(a => a.Key.Contains("grid1")), record);
                if (errors.Count > 0)
                {
                    return(Json(errors.First().errors.First().message));
                }

                errors = SaveChanges(Language);
                if (errors.Count > 0)
                {
                    return(Json(errors.First().errors.First().message));
                }

                model.Id = record.Id;

                // clear cache
                Response.RemoveOutputCacheItem(Url.Action("WorkFlow", "LeaveType"));

                return(Json("OK," + ((new JavaScriptSerializer()).Serialize(model))));
            }

            return(Json(Models.Utils.ParseFormErrors(ModelState)));
        }