Esempio n. 1
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)));
        }
Esempio n. 2
0
        public ActionResult DeleteSelected(string materialSpecificationId, string pageStates)
        {
            RequestResult result = new RequestResult();

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

                if ((Define.EnumFormAction)Session["MaterialFormAction"] == Define.EnumFormAction.Create)
                {
                    var model = Session["MaterialCreateFormModel"] as CreateFormModel;

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

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

                        model.MaterialSpecificationModels.Remove(model.MaterialSpecificationModels.First(x => x.MaterialSpecificationId == materialSpecificationId));

                        model.MaterialSpecificationModels = model.MaterialSpecificationModels.OrderBy(x => x.Seq).ToList();

                        int seq = 1;

                        foreach (var spec in model.MaterialSpecificationModels)
                        {
                            spec.Seq = seq;

                            seq++;
                        }

                        Session["MaterialCreateFormModel"] = model;

                        result.Success();
                    }
                }
                else if ((Define.EnumFormAction)Session["MaterialFormAction"] == Define.EnumFormAction.Edit)
                {
                    var model = Session["MaterialEditFormModel"] as EditFormModel;

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

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

                        model.MaterialSpecificationModels.Remove(model.MaterialSpecificationModels.First(x => x.MaterialSpecificationId == materialSpecificationId));

                        model.MaterialSpecificationModels = model.MaterialSpecificationModels.OrderBy(x => x.Seq).ToList();

                        int seq = 1;

                        foreach (var spec in model.MaterialSpecificationModels)
                        {
                            spec.Seq = seq;

                            seq++;
                        }

                        Session["MaterialEditFormModel"] = model;

                        result.Success();
                    }
                }
                else
                {
                    result.ReturnFailedMessage(Resources.Resource.UnKnownOperation);
                }
            }
            catch (Exception ex)
            {
                Error err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(Content(JsonConvert.SerializeObject(result)));
        }
Esempio n. 3
0
        public ActionResult AddSelect(string selecteds, string pageStates, string refOrganizationId)
        {
            RequestResult result = new RequestResult();

            try
            {
                List <string> selectedList = JsonConvert.DeserializeObject <List <string> >(selecteds);

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

                if ((Define.EnumFormAction)Session["MaterialFormAction"] == Define.EnumFormAction.Create)
                {
                    var model = Session["MaterialCreateFormModel"] as CreateFormModel;

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

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

                        result = MaterialDataAccessor.AddMaterialSpecification(model.MaterialSpecificationModels, selectedList, refOrganizationId);

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

                            Session["MaterialCreateFormModel"] = model;
                        }
                    }
                }
                else if ((Define.EnumFormAction)Session["MaterialFormAction"] == Define.EnumFormAction.Edit)
                {
                    var model = Session["MaterialEditFormModel"] as EditFormModel;

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

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

                        result = MaterialDataAccessor.AddMaterialSpecification(model.MaterialSpecificationModels, selectedList, refOrganizationId);

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

                            Session["MaterialEditFormModel"] = model;
                        }
                    }
                }
                else
                {
                    result.ReturnFailedMessage(Resources.Resource.UnKnownOperation);
                }
            }
            catch (Exception ex)
            {
                Error err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(Content(JsonConvert.SerializeObject(result)));
        }