Example #1
0
        public static RequestResult GetCopyFormModel(string abnormalReasonId)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var abnormalReason = context.AbnormalReasons.Include("Solutions").First(x => x.AbnormalReasonId == new Guid(abnormalReasonId));

                    var model = new CreateFormModel()
                    {
                        OrganizationId             = abnormalReason.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(abnormalReason.OrganizationId),
                        Types = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = Resources.Resource.Create + "...",
                                Value = Define.New
                            }
                        },
                        SolutionModels = abnormalReason.Solutions.Select(x => new SolutionModel
                        {
                            SolutionId = x.SolutionId.ToString(),
                            Type       = x.Type,
                            SId        = x.SId,
                            Name       = x.Name,
                        }).OrderBy(x => x.Type).ThenBy(x => x.SId).ToList(),
                        FormInput = new FormInput()
                        {
                            Type = abnormalReason.Type
                        }
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(abnormalReason.OrganizationId, true);

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

                    model.Types.First(x => x.Value == abnormalReason.Type).Selected = true;

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

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Example #2
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);
        }
Example #3
0
        public static RequestResult GetCopyFormModel(string equipmentSpecificationId)
        {
            RequestResult result = new RequestResult();

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

                    var model = new CreateFormModel()
                    {
                        OrganizationId             = spec.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(spec.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 = spec.EquipmentType
                        },
                        EquipmentSpecificationOptionModels = context.ESOptions.Where(x => x.ESpecificationId == spec.ESpecificationId).Select(x => new EquipmentSpecificationOptionModel
                        {
                            Name = x.Name,
                            Seq  = x.Seq
                        }).OrderBy(x => x.Seq).ToList()
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(spec.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());

                    model.EquipmentTypeSelectItems.First(x => x.Value == spec.EquipmentType).Selected = true;

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

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Example #4
0
        public static RequestResult GetCreateFormModel(string organizationId, string materialType)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var createFormModel = new CreateFormModel()
                    {
                        OrganizationId             = organizationId,
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(new Guid(organizationId)),
                        MaterialTypeSelectItems    = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = string.Format("{0}...", Resources.Resource.Create),
                                Value = Define.New
                            }
                        },
                        FormInput = new FormInput()
                        {
                            MaterialType = materialType
                        }
                    };

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

                    createFormModel.MaterialTypeSelectItems.AddRange(context.MSpecifications.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(materialType) && createFormModel.MaterialTypeSelectItems.Any(x => x.Value == materialType))
                    {
                        createFormModel.MaterialTypeSelectItems.First(x => x.Value == materialType).Selected = true;
                    }

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

                Logger.Log(err);

                requestResult.ReturnError(err);
            }

            return(requestResult);
        }
Example #5
0
        public static RequestResult GetCopyFormModel(Guid materialId)
        {
            RequestResult requestResult = new RequestResult();

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

                    var createFormModel = new CreateFormModel()
                    {
                        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
                        },
                        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
                            {
                                MaterialSpecificationId = o.MSpecificationId.ToString(),
                                Seq = o.Seq,
                                Name = o.Name,
                                MaterialSpecificationOptionId = o.MSOptionId.ToString()
                            }).OrderBy(o => o.Seq).ToList()
                        }).OrderBy(x => x.Seq).ToList()
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(material.OrganizationId, true);

                    createFormModel.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());

                    createFormModel.MaterialTypeSelectItems.First(x => x.Value == material.MaterialType).Selected = true;

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

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(requestResult);
        }
Example #6
0
        public static RequestResult GetEditFormModel(string materialSpecificationId)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var specification = context.MSpecifications.First(x => x.MSpecificationId == new Guid(materialSpecificationId));

                    var editFormModel = new EditFormModel()
                    {
                        MaterialSpecificationId    = specification.MSpecificationId.ToString(),
                        OrganizationId             = specification.OrganizationId.ToString(),
                        ParentOrganizationFullName = OrganizationDataAccessor.GetOrganizationFullName(specification.OrganizationId),
                        MaterialTypeSelectItems    = new List <SelectListItem>()
                        {
                            Define.DefaultSelectListItem(Resources.Resource.Select),
                            new SelectListItem()
                            {
                                Text  = string.Format("{0}...", Resources.Resource.Create),
                                Value = Define.New
                            }
                        },
                        FormInput = new FormInput()
                        {
                            MaterialType = specification.MaterialType,
                            Name         = specification.Name
                        },
                        MaterialSpecificationOptionModels = context.MSOptions.Where(x => x.MSpecificationId == specification.MSpecificationId).Select(x => new MaterialSpecificationOptionModel
                        {
                            MaterialSpecificationOptionId = x.MSOptionId.ToString(),
                            Name = x.Name,
                            Seq  = x.Seq
                        }).OrderBy(x => x.Seq).ToList()
                    };

                    var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(specification.OrganizationId, true);

                    editFormModel.MaterialTypeSelectItems.AddRange(context.MSpecifications.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(specification.MaterialType) && editFormModel.MaterialTypeSelectItems.Any(x => x.Value == specification.MaterialType))
                    {
                        editFormModel.MaterialTypeSelectItems.First(x => x.Value == specification.MaterialType).Selected = true;
                    }

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

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(requestResult);
        }