Пример #1
0
        public ActionResult Edit(EditFormModel editFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                var model = Session["CheckItemEditFormModel"] as EditFormModel;

                model.FormInput = editFormModel.FormInput;

                result = CheckItemDataAccessor.Edit(model);

                if (result.IsSuccess)
                {
                    Session.Remove("CheckItemFormAction");
                    Session.Remove("CheckItemEditFormModel");
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(Content(JsonConvert.SerializeObject(result)));
        }
Пример #2
0
        public ActionResult Edit(EditFormModel editFormModel)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                var model = Session["OrganizationEditFormModel"] as EditFormModel;
                model.FormInput = editFormModel.FormInput;
                requestResult   = OrganizationDataAccessor.Edit(model);
                if (requestResult.IsSuccess)
                {
                    HttpRuntime.Cache.Remove("Organizations");

                    Session.Remove("OrganizationFormAction");
                    Session.Remove("OrganizationEditFormModel");

                    var account = Session["Account"] as Account;
                    account.OrganizationPermissions = OrganizationDataAccessor.GetOrganizationPermissions(account.OrganizationId);
                    Session["Account"] = account;
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(Content(JsonConvert.SerializeObject(requestResult)));
        }
Пример #3
0
        public static RequestResult GetEditFormModel(string solutionId)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var solution = context.Solutions.First(x => x.SolutionId == new Guid(solutionId));

                    var model = new EditFormModel()
                    {
                        SolutionId                 = solution.SolutionId.ToString(),
                        OrganizationId             = solution.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(solution.OrganizationId),
                        SolutionTypes              = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = Resources.Resource.Create + "...",
                                Value = Define.New
                            }
                        },
                        FormInput = new FormInput()
                        {
                            Type = solution.Type,
                            SId  = solution.SId,
                            Name = solution.Name
                        }
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(new Guid(model.OrganizationId), true);

                    model.SolutionTypes.AddRange(context.Solutions.Where(x => upStreamOrganizationIds.Contains(x.OrganizationId)).Select(x => x.Type).Distinct().OrderBy(x => x).Select(x => new SelectListItem
                    {
                        Value = x,
                        Text  = x
                    }).ToList());

                    if (!string.IsNullOrEmpty(model.FormInput.Type) && model.SolutionTypes.Any(x => x.Value == model.FormInput.Type))
                    {
                        model.SolutionTypes.First(x => x.Value == model.FormInput.Type).Selected = true;
                    }

                    result.ReturnData(model);
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Пример #4
0
        private static void EditButtonClick(object o, EventArgs e)
        {
            var view       = new EditFormView();
            var model      = new EditFormModel();
            var controller = new EditFormController(model, view);

            view.ShowDialog();
        }
Пример #5
0
        public IActionResult Get(Guid entityid)
        {
            EditFormModel model = new EditFormModel
            {
                SolutionId = SolutionId.Value,
                EntityId   = entityid
            };

            return(JOk(model));
        }
Пример #6
0
        public IActionResult CreateForm(Guid entityid)
        {
            EditFormModel model = new EditFormModel
            {
                SolutionId = SolutionId.Value,
                EntityId   = entityid
            };

            return(View(model));
        }
Пример #7
0
        public static object Edit(EditFormModel editFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                if (editFormModel.FormInput.Type == Define.Other || editFormModel.FormInput.Type == Define.New)
                {
                    result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.SolutionType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var solution = context.Solutions.First(x => x.SolutionId == new Guid(editFormModel.SolutionId));

                        var exists = context.Solutions.FirstOrDefault(x => x.SolutionId != solution.SolutionId && x.OrganizationId == solution.OrganizationId && x.Type == editFormModel.FormInput.Type && x.SId == editFormModel.FormInput.SId);

                        if (exists == null)
                        {
#if !DEBUG
                            using (TransactionScope trans = new TransactionScope())
                            {
#endif
                            solution.Type           = editFormModel.FormInput.Type;
                            solution.SId            = editFormModel.FormInput.SId;
                            solution.Name           = editFormModel.FormInput.Name;
                            solution.LastModifyTime = DateTime.Now;

                            context.SaveChanges();
#if !DEBUG
                            trans.Complete();
                        }
#endif
                            result.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Solution, Resources.Resource.Success));
                        }
                        else
                        {
                            result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.SId, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Пример #8
0
        public ActionResult Edit(EditFormModel editFormModel)
        {
            RequestResult result = PersonDataAccessor.Edit(editFormModel);

            if (result.IsSuccess)
            {
                HttpRuntime.Cache.Remove("Users");
            }

            return(Content(JsonConvert.SerializeObject(result)));
        }
Пример #9
0
 public IActionResult Post(EditFormModel model)
 {
     if (ModelState.IsValid)
     {
         var entity = _systemFormFinder.FindById(model.SystemFormId);
         model.CopyTo(entity);
         entity.ModifiedBy = CurrentUser.SystemUserId;
         entity.ModifiedOn = DateTime.Now;
         _systemFormUpdater.Update(entity, true);
         return(UpdateSuccess(new { id = entity.SystemFormId }));
     }
     return(UpdateFailure(GetModelErrors()));
 }
Пример #10
0
        /// <summary>
        /// Генерация представления для формы редактирования
        /// </summary>
        protected ActionResult EditView <TModel>(TModel model, Func <ActionResult> action, string title, string subtitle, string submitTitle)
        {
            var editFormModel = new EditFormModel {
                Model = model
            };

            editFormModel.Title       = title;
            editFormModel.SubTitle    = subtitle;
            editFormModel.Action      = action.Method.Name;
            editFormModel.Controller  = CurrentControllerName();
            editFormModel.ButtonTitle = submitTitle;
            return(View(Views.Default.Edit, editFormModel));
        }
Пример #11
0
 public IActionResult CreateForm(EditFormModel model)
 {
     if (ModelState.IsValid)
     {
         var entity = new SystemForm();
         model.CopyTo(entity);
         entity.SystemFormId = Guid.NewGuid();
         entity.StateCode    = RecordState.Enabled;
         entity.FormType     = (int)FormType.Main;
         _systemFormCreater.Create(entity);
         return(CreateSuccess(new { id = entity.SystemFormId }));
     }
     return(CreateFailure(GetModelErrors()));
 }
Пример #12
0
        public IActionResult Get(Guid id)
        {
            EditFormModel model = new EditFormModel();

            if (!id.Equals(Guid.Empty))
            {
                var entity = _systemFormFinder.FindById(id);
                if (entity != null)
                {
                    entity.CopyTo(model);
                    return(JOk(model));
                }
            }
            return(NotFound());
        }
Пример #13
0
        public ActionResult Edit(EditFormModel editFormModel)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                var model = Session["RoleEditFormModel"] as EditFormModel;
                model.FormInput = editFormModel.FormInput;
                requestResult   = RoleDataAccessor.Edit(model);
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(Content(JsonConvert.SerializeObject(requestResult)));
        }
Пример #14
0
        public ActionResult Edit(EditFormModel editFormModel, string pageStates)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                var model = Session["MaterialEditFormModel"] as EditFormModel;

                var pageStateList = JsonConvert.DeserializeObject <List <string> >(pageStates);

                requestResult = MaterialDataAccessor.SavePageState(model.MaterialSpecificationModels, pageStateList);

                if (requestResult.IsSuccess)
                {
                    model.MaterialSpecificationModels = requestResult.Data as List <MaterialSpecificationModel>;

                    model.FormInput = editFormModel.FormInput;

                    requestResult = MaterialDataAccessor.Edit(model);

                    if (requestResult.IsSuccess)
                    {
                        Session.Remove("MaterialFormAction");
                        Session.Remove("MaterialEditFormModel");
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(Content(JsonConvert.SerializeObject(requestResult)));
        }
Пример #15
0
        public static RequestResult Edit(EditFormModel editFormModel)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var person = context.People.Include("Roles").First(x => x.LoginId == editFormModel.PId);

                    bool exceedsLimit = false;

                    if (editFormModel.FormInput.IsMobilePerson)
                    {
                        var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(person.OrganizationId, true);

                        PopulationLimit populationLimit = null;

                        foreach (var item in Config.PopulationLimits)
                        {
                            if (upStreamOrganizationIds.Contains(item.OrganizationId))
                            {
                                populationLimit = item;

                                break;
                            }
                        }

                        if (populationLimit != null)
                        {
                            var organization = OrganizationDataAccessor.GetOrganization(populationLimit.OrganizationId);

                            var downStreamOrganizations = OrganizationDataAccessor.GetDownStreamOrganizations(populationLimit.OrganizationId, true);

                            var mobilePeople = context.People.Where(x => x.LoginId != person.LoginId && x.IsMobilePerson && downStreamOrganizations.Contains(x.OrganizationId)).ToList();

                            if (mobilePeople.Count + 1 > populationLimit.NumberOfMobilePeople)
                            {
                                exceedsLimit = true;

                                requestResult.ReturnFailedMessage(string.Format(Resources.Resource.ExceedsMobilePopulationLimit, organization.Name, populationLimit.NumberOfMobilePeople));
                            }
                        }
                    }

                    if (!exceedsLimit)
                    {
#if !DEBUG
                        using (TransactionScope trans = new TransactionScope())
                        {
#endif
                        #region Person
                        person.Name  = editFormModel.FormInput.Name;
                        person.Title = editFormModel.FormInput.Title;
                        person.Email = editFormModel.FormInput.EMail;
                        //person.UID = editFormModel.FormInput.UID;
                        person.IsMobilePerson = editFormModel.FormInput.IsMobilePerson;
                        person.LastModifyTime = DateTime.Now;

                        context.SaveChanges();
                        #endregion

                        #region PersonRoles
                        #region Delete
                        if (person != null)
                        {
                            person.Roles = new List <CF.Models.Role>();
                            context.SaveChanges();
                        }

                        #endregion

                        #region Insert
                        foreach (var roleId in editFormModel.FormInput.RoleIds)
                        {
                            var role = context.Roles.First(r => r.RoleId == roleId);
                            person.Roles.Add(role);
                        }
                        context.SaveChanges();
                        #endregion
                        #endregion
#if !DEBUG
                        trans.Complete();
                    }
#endif
                        requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Person, Resources.Resource.Success));
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Пример #16
0
 public ActionResult Edit(EditFormModel editFormModel)
 {
     return(Content(JsonConvert.SerializeObject(SolutionDataAccessor.Edit(editFormModel))));
 }
Пример #17
0
        public static RequestResult Edit(EditFormModel editFormModel)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                if (editFormModel.FormInput.MaterialType == Define.New)
                {
                    requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.MaterialType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var material = context.Materials.First(x => x.MaterialId == new Guid(editFormModel.MaterialId));

                        var exists = context.Materials.FirstOrDefault(x => x.MaterialId != material.MaterialId && x.OrganizationId == material.OrganizationId && x.MaterialType == editFormModel.FormInput.MaterialType && x.MId == editFormModel.FormInput.MId);

                        if (exists == null)
                        {
#if !DEBUG
                            using (TransactionScope trans = new TransactionScope())
                            {
#endif
                            #region Materials
                            material.MaterialType = editFormModel.FormInput.MaterialType;
                            material.MId          = editFormModel.FormInput.MId;
                            material.Name         = editFormModel.FormInput.MaterialName;
                            //material.Quantity = Model.FormInput.Quantity.HasValue ? Model.FormInput.Quantity.Value : 0;

                            context.SaveChanges();
                            #endregion

                            #region MaterialSpecificationOptionValue
                            #region Delete
                            context.MaterialSpecificationOptions.RemoveRange(context.MaterialSpecificationOptions.Where(x => x.MaterialId == new Guid(editFormModel.MaterialId)).ToList());

                            context.SaveChanges();
                            #endregion

                            #region Insert
                            context.MaterialSpecificationOptions.AddRange(editFormModel.MaterialSpecificationModels.Select(x => new CF.Models.Maintenance.MaterialSpecificationOption
                            {
                                MaterialId       = new Guid(editFormModel.MaterialId),
                                MSpecificationId = new Guid(x.MaterialSpecificationId),
                                MSOptionId       = new Guid(x.MaterialSpecificationOptionId),
                                Value            = x.Value,
                                Seq = x.Seq
                            }).ToList());

                            context.SaveChanges();
                            #endregion
                            #endregion

                            requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Material, Resources.Resource.Success));
#if !DEBUG
                            trans.Complete();
                        }
#endif
                        }
                        else
                        {
                            requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.MId, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(requestResult);
        }
Пример #18
0
        public static RequestResult GetEditFormModel(Guid materialId)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var material = context.Materials.First(x => x.MaterialId == materialId);

                    var model = new EditFormModel()
                    {
                        MaterialId                 = material.MaterialId.ToString(),
                        OrganizationId             = material.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(material.OrganizationId),
                        MaterialTypeSelectItems    = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = Resources.Resource.Create + "...",
                                Value = Define.New
                            }
                        },
                        FormInput = new FormInput()
                        {
                            MaterialType = material.MaterialType,
                            MId          = material.MId,
                            MaterialName = material.Name,
                            Quantity     = material.Quantity
                        },
                        MaterialSpecificationModels = (from x in context.MaterialSpecificationOptions
                                                       join s in context.MSpecifications
                                                       on x.MSpecificationId equals s.MSpecificationId
                                                       where x.MaterialId == material.MaterialId
                                                       select new MaterialSpecificationModel
                        {
                            MaterialSpecificationId = s.MSpecificationId.ToString(),
                            Name = s.Name,
                            MaterialSpecificationOptionId = x.MSOptionId.ToString(),
                            Value = x.Value,
                            Seq = x.Seq,
                            MaterialSpecificationOptionModels = context.MSOptions.Where(o => o.MSpecificationId == s.MSpecificationId).Select(o => new MaterialSpecificationOptionModel
                            {
                                MaterialSpecificationOptionId = o.MSOptionId.ToString(),
                                Name = o.Name,
                                Seq = o.Seq,
                                MaterialSpecificationId = o.MSpecificationId.ToString()
                            }).OrderBy(o => o.Name).ToList()
                        }).OrderBy(x => x.Seq).ToList()
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(new Guid(model.OrganizationId), true);

                    model.MaterialTypeSelectItems.AddRange(context.Materials.Where(x => upStreamOrganizationIds.Contains(x.OrganizationId)).Select(x => x.MaterialType).Distinct().OrderBy(x => x).Select(x => new SelectListItem
                    {
                        Value = x,
                        Text  = x
                    }).ToList());

                    if (!string.IsNullOrEmpty(model.FormInput.MaterialType) && model.MaterialTypeSelectItems.Any(x => x.Value == model.FormInput.MaterialType))
                    {
                        model.MaterialTypeSelectItems.First(x => x.Value == model.FormInput.MaterialType).Selected = true;
                    }

                    requestResult.ReturnData(model);
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(requestResult);
        }
Пример #19
0
        public static object Edit(EditFormModel editFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                if (editFormModel.FormInput.EquipmentType == Define.New)
                {
                    result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.EquipmentType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var spec = context.ESpecifications.First(x => x.ESpecificationId == new Guid(editFormModel.EquipmentSpecificationId));

                        var exists = context.ESpecifications.FirstOrDefault(x => x.ESpecificationId != spec.ESpecificationId && x.OrganizationId == spec.OrganizationId && x.EquipmentType == editFormModel.FormInput.EquipmentType && x.Name == editFormModel.FormInput.Name);

                        if (exists == null)
                        {
#if !DEBUG
                            using (TransactionScope trans = new TransactionScope())
                            {
#endif
                            #region EquipmentSpecification
                            spec.EquipmentType = editFormModel.FormInput.EquipmentType;
                            spec.Name          = editFormModel.FormInput.Name;

                            context.SaveChanges();
                            #endregion

                            #region EquipmentSpecificationOption
                            #region Delete
                            context.EquipmentSpecificationOptions.RemoveRange(context.EquipmentSpecificationOptions.Where(x => x.ESpecificationId == new Guid(editFormModel.EquipmentSpecificationId)).ToList());

                            context.SaveChanges();
                            #endregion

                            #region Insert
                            context.ESOptions.AddRange(editFormModel.FormInput.EquipmentSpecificationOptionModels.Select(x => new CF.Models.Maintenance.ESOption
                            {
                                ESOptionId       = !string.IsNullOrEmpty(x.EquipmentSpecificationOptionId) ? new Guid(x.EquipmentSpecificationOptionId) : Guid.NewGuid(),
                                ESpecificationId = spec.ESpecificationId,
                                Name             = x.Name,
                                Seq = x.Seq
                            }).ToList());

                            context.SaveChanges();
                            #endregion
                            #endregion

                            #region EquipmentSpecificationOptionValue
                            var optionList = editFormModel.FormInput.EquipmentSpecificationOptionModels.Where(x => !string.IsNullOrEmpty(x.EquipmentSpecificationOptionId)).Select(x => x.EquipmentSpecificationOptionId).ToList();

                            var specValueList = context.EquipmentSpecificationOptions.Where(x => x.ESpecificationId == spec.ESpecificationId && !optionList.Contains(x.ESOptionId.ToString())).ToList();

                            foreach (var specValue in specValueList)
                            {
                                specValue.ESOptionId = Guid.Empty;
                            }

                            context.SaveChanges();
                            #endregion
#if !DEBUG
                            trans.Complete();
                        }
#endif
                            result.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.EquipmentSpecification, Resources.Resource.Success));
                        }
                        else
                        {
                            result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.EquipmentSpecificationName, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Пример #20
0
        public static RequestResult GetEditFormModel(string equipmentSpecificationId)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var query = context.ESpecifications.First(x => x.ESpecificationId == new Guid(equipmentSpecificationId));

                    var model = new EditFormModel()
                    {
                        EquipmentSpecificationId   = query.ESpecificationId.ToString(),
                        OrganizationId             = query.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(query.OrganizationId),
                        EquipmentTypeSelectItems   = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = string.Format("{0}...", Resources.Resource.Create),
                                Value = Define.New
                            }
                        },
                        FormInput = new FormInput()
                        {
                            EquipmentType = query.EquipmentType,
                            Name          = query.Name
                        },
                        EquipmentSpecificationOptionModels = context.ESOptions.Where(x => x.ESpecificationId == query.ESpecificationId).Select(x => new EquipmentSpecificationOptionModel
                        {
                            EquipmentSpecificationOptionId = x.ESOptionId.ToString(),
                            Name = x.Name,
                            Seq  = x.Seq
                        }).OrderBy(x => x.Seq).ToList()
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(new Guid(model.OrganizationId), true);

                    model.EquipmentTypeSelectItems.AddRange(context.ESpecifications.Where(x => upStreamOrganizationIds.Contains(x.OrganizationId)).Select(x => x.EquipmentType).Distinct().OrderBy(x => x).Select(x => new SelectListItem
                    {
                        Value = x,
                        Text  = x
                    }).ToList());

                    if (!string.IsNullOrEmpty(model.FormInput.EquipmentType) && model.EquipmentTypeSelectItems.Any(x => x.Value == model.FormInput.EquipmentType))
                    {
                        model.EquipmentTypeSelectItems.First(x => x.Value == model.FormInput.EquipmentType).Selected = true;
                    }

                    result.ReturnData(model);
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Пример #21
0
        public static RequestResult Edit(EditFormModel editFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                if (editFormModel.FormInput.Type == Define.Other || editFormModel.FormInput.Type == Define.New)
                {
                    result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.AbnormalReasonType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var abnormalReason = context.AbnormalReasons.Include("Soutions").First(x => x.AbnormalReasonId == new Guid(editFormModel.AbnormalReasonId));

                        var exists = context.AbnormalReasons.FirstOrDefault(x => x.AbnormalReasonId != abnormalReason.AbnormalReasonId && x.OrganizationId == abnormalReason.OrganizationId && x.Type == editFormModel.FormInput.Type && x.ARId == editFormModel.FormInput.ARId);

                        if (exists == null)
                        {
#if !DEBUG
                            using (TransactionScope trans = new TransactionScope())
                            {
#endif
                            #region AbnormalReason
                            abnormalReason.Type           = editFormModel.FormInput.Type;
                            abnormalReason.ARId           = editFormModel.FormInput.ARId;
                            abnormalReason.Name           = editFormModel.FormInput.Name;
                            abnormalReason.LastModifyTime = DateTime.Now;

                            context.SaveChanges();
                            #endregion

                            #region AbnormalReasonHandlingMethod
                            #region Delete
                            abnormalReason.Solutions = new HashSet <CF.Models.Maintenance.Solution>();
                            context.SaveChanges();
                            #endregion

                            #region Insert
                            abnormalReason.Solutions = editFormModel.SolutionModels.Select(x => new CF.Models.Maintenance.Solution()
                            {
                                SolutionId     = new Guid(x.SolutionId),
                                SId            = x.SId,
                                Name           = x.Name,
                                Type           = x.Type,
                                OrganizationId = new Guid(editFormModel.OrganizationId)
                            }).ToList();
                            context.SaveChanges();
                            #endregion
                            #endregion
#if !DEBUG
                            trans.Complete();
                        }
#endif
                            result.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.AbnormalReason, Resources.Resource.Success));
                        }
                        else
                        {
                            result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.ARId, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Пример #22
0
 public virtual void SetWarning(EditFormModel r, IGuidIdentifiedEntity item)
 {
 }
Пример #23
0
        public static RequestResult Edit(EditFormModel editFormModel)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
#if !DEBUG
                    using (TransactionScope trans = new TransactionScope())
                    {
#endif
                    #region Role
                    var role = context.Roles.Include("People").First(x => x.RoleId == editFormModel.RoleId);

                    role.Name = editFormModel.FormInput.Name;

                    context.SaveChanges();
                    #endregion

                    #region RoleWebPermissionFunction
                    #region Delete
                    context.RolePermissionFunctions.RemoveRange(context.RolePermissionFunctions.Where(x => x.RoleId == role.RoleId).ToList());

                    context.SaveChanges();
                    #endregion

                    #region Insert
                    context.RolePermissionFunctions.AddRange(editFormModel.FormInput.WebPermissionFunctionList.Select(x => new CF.Models.RolePermissionFunction
                    {
                        RoleId          = role.RoleId,
                        WebPermissionId = x.WebPermissionId,
                        WebFunctionId   = x.WebFunctionId
                    }).ToList());

                    context.SaveChanges();
                    #endregion
                    #endregion

                    #region RolePeople
                    #region Delete
                    role.People = new List <CF.Models.Person>();

                    context.SaveChanges();
                    #endregion

                    #region Insert
                    var pIds = editFormModel.People.Select(p => p.PId);
                    role.People = context.People.Where(p => pIds.Contains(p.LoginId)).ToList();

                    context.SaveChanges();
                    #endregion
                    #endregion
#if !DEBUG
                    trans.Complete();
                }
#endif

                    requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Role, Resources.Resource.Success));
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Пример #24
0
        public static RequestResult Edit(EditFormModel model)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var organization = context.Organizations.First(o => o.OrganizationId.ToString() == model.OrganizationId);
                    var exists       = context.Organizations.FirstOrDefault(o => o.OrganizationId != organization.OrganizationId && o.ParentId == organization.ParentId && o.OId == model.FormInput.OId);
                    if (exists == null)
                    {
                        organization.OId  = model.FormInput.OId;
                        organization.Name = model.FormInput.Name;

                        context.SaveChanges();

                        context.OrganizationManagers.RemoveRange(context.OrganizationManagers.Where(o => o.OrganizationId.ToString() == model.OrganizationId));
                        context.EditableOrganizations.RemoveRange(context.EditableOrganizations.Where(o => o.OrganizationId.ToString() == model.OrganizationId));
                        context.QueryableOrganizations.RemoveRange(context.QueryableOrganizations.Where(o => o.OrganizationId.ToString() == model.OrganizationId));

                        context.SaveChanges();

                        if (!string.IsNullOrEmpty(model.FormInput.Managers))
                        {
                            string organizationId = model.OrganizationId;
                            context.OrganizationManagers.AddRange(model.FormInput.Managers.Split(',').ToList().Select(o => new OrganizationManager()
                            {
                                OrganizationId = new Guid(organizationId),
                                ManagerId      = o
                            }));
                        }

                        context.EditableOrganizations.AddRange(model.EditableOrganizations.Where(e => e.CanDelete).Select(e => new EditableOrganization
                        {
                            OrganizationId         = new Guid(model.OrganizationId),
                            EditableOrganizationId = e.OrganizationId
                        }));

                        context.QueryableOrganizations.AddRange(model.QueryableOrganizations.Select(q => new QueryableOrganization
                        {
                            OrganizationId          = new Guid(model.OrganizationId),
                            QueryableOrganizationId = q.OrganizationId
                        }));

                        context.SaveChanges();

                        requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Organization, Resources.Resource.Success));
                    }
                    else
                    {
                        requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.OrganizationId, Resources.Resource.Exists));
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Пример #25
0
        public static RequestResult Edit(EditFormModel editFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var checkpoint = context.Checkpoints.Include("CheckItems").First(x => x.CheckpointId == new Guid(editFormModel.CheckpointId));

                    var exists = context.Checkpoints.FirstOrDefault(x => x.CheckpointId != checkpoint.CheckpointId && x.OrganizationId == checkpoint.OrganizationId && x.CId == editFormModel.FormInput.CId);

                    if (exists == null)
                    {
                        if (!string.IsNullOrEmpty(editFormModel.FormInput.TagId) && context.Checkpoints.Any(x => x.CheckpointId != checkpoint.CheckpointId && x.TagId == editFormModel.FormInput.TagId))
                        {
                            var query = context.Checkpoints.First(x => x.CheckpointId != checkpoint.CheckpointId && x.TagId == editFormModel.FormInput.TagId);

                            var organization = OrganizationDataAccessor.GetOrganization(query.OrganizationId);

                            result.ReturnFailedMessage(string.Format("{0} {1} {2} {3} {4}", Resources.Resource.TagId, editFormModel.FormInput.TagId, Resources.Resource.Exists, organization.Name, checkpoint.Name));
                        }
                        else
                        {
            #if !DEBUG
                    using (TransactionScope trans = new TransactionScope())
                    {
            #endif
                            #region ControlPoint
                            checkpoint.CId = editFormModel.FormInput.CId;
                            checkpoint.Name = editFormModel.FormInput.Name;
                            checkpoint.TagId = editFormModel.FormInput.TagId;
                            checkpoint.Remark = editFormModel.FormInput.Remark;
                            checkpoint.IsFeelItemDefaultNormal = editFormModel.FormInput.IsFeelItemDefaultNormal;
                            checkpoint.LastModifyTime = DateTime.Now;

                            context.SaveChanges();
                            #endregion

                            #region CheckItems
                            #region Delete
                            checkpoint.CheckItems = new HashSet<CheckItem>();

                            context.SaveChanges();
                            #endregion

                            #region Insert
                            checkpoint.CheckItems = editFormModel.CheckItemModels.Select(x => new CheckItem()
                            {
                                CheckItemId = new Guid(x.CheckItemId),
                                CIId = x.CIId,
                                Name = x.Name,
                                Type = x.Type,
                                IsInherit = x.IsInherit,
                                IsFeelItem = x.IsFeelItem,
                                IsAccumulation = x.IsAccumulation,
                                LowerLimit = x.LowerLimit,
                                LowerAlertLimit = x.LowerAlertLimit,
                                UpperLimit = x.UpperLimit,
                                UpperAlertLimit = x.UpperAlertLimit,
                                Unit = x.Unit,
                                Remark = x.Remark,
                                AccumulationBase = x.AccumulationBase,
                                LastModifyTime = DateTime.Now
                            }).ToList();

                            context.SaveChanges();
                            #endregion
                            #endregion
            #if !DEBUG
                        trans.Complete();
                    }
            #endif
                            result.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Checkpoint, Resources.Resource.Success));
                        }
                    }
                    else
                    {
                        result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Checkpoint, Resources.Resource.Exists));
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return result;
        }