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)); }
/// <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)); }
/// <summary> /// partner section list. /// </summary> /// <returns></returns> public async Task <ActionResult> GetPartners() { PartnersViewData partnerViewData = new PartnersViewData(); PartnerResultData result = await WebApiClient.GetAsync <PartnerResultData>(Constant.WebApiControllerPartners, Constant.WebApiPartnerList); if (result?.PartnerDtoList != null && result.OperationSuccess) { partnerViewData.Partners = result.PartnerDtoList; } return(PartialView("Partials/_PartnersList", partnerViewData)); }
/// <summary> /// Get Partners /// </summary> /// <returns></returns> private async Task <PartnersViewData> GetPartners() { PartnersViewData partnerViewData = new PartnersViewData(); PartnerResultData result = await WebApiClient.GetAsync <PartnerResultData>(Constant.WebApiControllerPartners, Constant.WebApiPartnerList); if (result?.PartnerDtoList != null && result.OperationSuccess) { partnerViewData.Partners = result.PartnerDtoList; } return(partnerViewData); }
/// <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); }
/// <summary> /// The index page. /// </summary> /// <returns></returns> public async Task <ActionResult> Index() { if (Session["ConnectedUser"] == null) { return(RedirectToAction("Index", "Home")); } bool isAuthorizedUser = await AuthorizeUserAttribute.Authorize("A_PARTNERS"); if (!isAuthorizedUser) { return(RedirectToAction("NoAccess", "Errors")); } PartnersViewData partnerViewData = new PartnersViewData(); PartnerResultData result = await WebApiClient.GetAsync <PartnerResultData>(Constant.WebApiControllerPartners, Constant.WebApiPartnerList); if (result?.PartnerDtoList != null && result.OperationSuccess) { partnerViewData.Partners = result.PartnerDtoList; } ViewBag.Partners = "active"; return(View(partnerViewData)); }
public async Task <OmsJsonResult> DeletePartner(int partnerId) { JsonReturnData data = new JsonReturnData(); if (partnerId > 0) { string param = $"{nameof(partnerId)}={partnerId}"; PartnerResultData result = await WebApiClient.DeleteAsync <PartnerResultData>(Constant.WebApiControllerPartners, Constant.WebApiRemovePartner, param); 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/" + partnerId))) { Directory.Delete(Server.MapPath($"~/Images/Partners/" + partnerId), true); } data.SuccessMessage = UserResources.Ok; data.OperationSuccess = true; } } else { data.ErrorMessage = PartnerResources.RequiredId; data.OperationSuccess = false; } return(new OmsJsonResult(data)); }