Пример #1
0
        public async Task <OmsJsonResult> UpdatePartner(PartnerFormData partnerFormData)
        {
            PartnerRequestData request = partnerFormData.ToRequestData();
            PartnerResultData  result  = await WebApiClient.PostFormJsonAsync <PartnerRequestData, PartnerResultData>(Constant.WebApiControllerPartners, Constant.WebApiUpdatePartner, request);

            JsonReturnData data = new JsonReturnData();

            if (result == null)
            {
                data.ErrorMessage     = SharedResources.ServerError;
                data.OperationSuccess = false;
            }
            else if (!result.OperationSuccess && result.Errors != null && result.Errors.Count > 0)
            {
                data.ErrorMessage     = result.Errors.First();
                data.OperationSuccess = false;
            }
            else if (result.OperationSuccess)
            {
                if (!Directory.Exists(Server.MapPath($"~/Images/Partners/" + partnerFormData.PartnerId + $"/")))
                {
                    Directory.CreateDirectory(
                        Server.MapPath($"~/Images/Partners/" + partnerFormData.PartnerId));
                }

                partnerFormData.PartnerImage?.SaveAs(
                    Server.MapPath($"~/Images/Partners/" + partnerFormData.PartnerId + $"/") +
                    partnerFormData.PartnerImage.FileName);

                data.SuccessMessage   = UserResources.Ok;
                data.OperationSuccess = true;
            }
            return(new OmsJsonResult(data));
        }
Пример #2
0
        /// <summary>
        /// Return the view to add partner.
        /// </summary>
        /// <returns>adding view</returns>
        public ActionResult GetCreatePartner()
        {
            PartnerFormData partnerFormData = new PartnerFormData();

            ViewBag.Action = "CreatePartner";
            return(PartialView("Partials/_ManagePartner", partnerFormData));
        }
Пример #3
0
        /// <summary>
        /// The update partner view.
        /// </summary>
        /// <param name="partnerId">the partner id to update.</param>
        /// <returns>updating view</returns>
        public async Task <ActionResult> GetUpdatePartner(int partnerId)
        {
            PartnerFormData    partnerFormData = new PartnerFormData();
            PartnerRequestData findRequest     = new PartnerRequestData
            {
                PartnerDto = new PartnerItemData
                {
                    PartnerId = partnerId
                },
                FindPartnerDto = FindPartnerItemData.PartnerId
            };

            PartnerResultData result = await WebApiClient.PostFormJsonAsync <PartnerRequestData, PartnerResultData>(Constant.WebApiControllerPartners, Constant.WebApiFindPartners, findRequest);

            if (result != null && result.OperationSuccess && result.PartnerDto != null)
            {
                partnerFormData = result.ToFormData();
            }

            List <SelectListItem> positionList  = new List <SelectListItem>();
            PartnerResultData     partnerResult = await WebApiClient.GetAsync <PartnerResultData>(Constant.WebApiControllerPartners, Constant.WebApiPartnerList);

            foreach (var partner in partnerResult.PartnerDtoList.OrderBy(p => p.PartnerPosition))
            {
                positionList.Add(new SelectListItem {
                    Text = PartnerResources.PositionText + partner.PartnerPosition, Value = partner.PartnerPosition.ToString()
                });
            }
            ViewBag.positionList = positionList;

            ViewBag.Action = "UpdatePartner";
            return(PartialView("Partials/_ManagePartner", partnerFormData));
        }
Пример #4
0
 /// <summary>
 /// From FORMDATA To REQUESTDATA
 /// </summary>
 /// <param name="subscriberFormData"></param>
 /// <returns></returns>
 public static PartnerRequestData ToRequestData(this PartnerFormData subscriberFormData)
 {
     if (subscriberFormData == null)
     {
         return(new PartnerRequestData());
     }
     return(new PartnerRequestData
     {
         PartnerDto = subscriberFormData.ToItemData()
     });
 }
Пример #5
0
        /// <summary>
        /// FROM ITEM DATA TO FORM DATA.
        /// </summary>
        /// <param name="resultData">the itemData to convert</param>
        /// <returns>the formdata result</returns>
        public static PartnerFormData ToFormData(this PartnerResultData resultData)
        {
            if (resultData == null)
            {
                return(new PartnerFormData());
            }

            PartnerFormData formData = new PartnerFormData
            {
                PartnerId       = resultData.PartnerDto.PartnerId,
                PartnerPosition = resultData.PartnerDto.PartnerPosition,
                PartnerLink     = resultData.PartnerDto.PartnerLink,
                PartnerName     = resultData.PartnerDto.PartnerName,
            };

            return(formData);
        }
Пример #6
0
        /// <summary>
        /// FROM ITEM DATA TO FORM DATA.
        /// </summary>
        /// <param name="itemData">the itemData to convert</param>
        /// <returns>the formdata result</returns>
        public static PartnerFormData ToFormData(this PartnerItemData itemData)
        {
            if (itemData == null)
            {
                return(new PartnerFormData());
            }

            PartnerFormData formData = new PartnerFormData
            {
                PartnerId       = itemData.PartnerId,
                PartnerPosition = itemData.PartnerPosition,
                PartnerLink     = itemData.PartnerLink,
                PartnerName     = itemData.PartnerName,
            };

            return(formData);
        }
Пример #7
0
        /// <summary>
        /// FROM FROMDATA TO ITEMDATA.
        /// </summary>
        /// <param name="formData">the formdata to convert</param>
        /// <returns>the item data.</returns>
        public static PartnerItemData ToItemData(this PartnerFormData formData)
        {
            if (formData == null)
            {
                return(new PartnerItemData());
            }

            PartnerItemData itemData = new PartnerItemData
            {
                PartnerPosition = formData.PartnerPosition,
                PartnerLink     = formData.PartnerLink,
                PartnerName     = formData.PartnerName,
                PartnerImage    = formData.PartnerImage?.FileName,
                PartnerId       = formData.PartnerId
            };

            return(itemData);
        }