public async Task <IActionResult> Create([FromBody] PaymentCreateRequest request) { var result = await _paymentService.Create(request); if (!result.IsSuccess) { return(BadRequest(result)); } return(Ok(result)); }
public ActionResult Create(PaymentMethodViewModel model, string returnUrl) { ActionResult action; try { if (!ModelState.IsValid) { ModelState.AddModelError("", MessageUI.ErrorMessage); return(View(model)); } if (model.Image != null && model.Image.ContentLength > 0) { var fileExtension = Path.GetExtension(model.Image.FileName); var fileNameOriginal = Path.GetFileNameWithoutExtension(model.Image.FileName); var fileName = fileNameOriginal.FileNameFormat(fileExtension); _imagePlugin.CropAndResizeImage(model.Image, $"{Contains.PaymentMethodFolder}", fileName, ImageSize.PaymentMethodWithMediumSize, ImageSize.PaymentMethodHeightMediumSize); model.ImageUrl = string.Concat(Contains.PaymentMethodFolder, fileName); } var modelMap = Mapper.Map <PaymentMethodViewModel, PaymentMethod>(model); _paymentMethodService.Create(modelMap); //Update Localized foreach (var localized in model.Locales) { _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.PaymentMethodSystemName, localized.PaymentMethodSystemName, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId); } Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.PaymentMethod))); if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\")) { action = RedirectToAction("Index"); } else { action = Redirect(returnUrl); } } catch (Exception ex) { ExtentionUtils.Log(string.Concat("PaymentMethod.Create: ", ex.Message)); ModelState.AddModelError("", ex.Message); return(View(model)); } return(action); }
public ActionResult Create(PaymentMethodViewModel model, string returnUrl) { ActionResult action; try { if (!ModelState.IsValid) { ModelState.AddModelError("", MessageUI.ErrorMessage); return(View(model)); } ImageHandler(model); var modelMap = Mapper.Map <PaymentMethodViewModel, PaymentMethod>(model); _paymentMethodService.Create(modelMap); //Update Localized foreach (var localized in model.Locales) { _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.PaymentMethodSystemName, localized.PaymentMethodSystemName, localized.LanguageId); _localizedPropertyService.SaveLocalizedValue(modelMap, x => x.Description, localized.Description, localized.LanguageId); } Response.Cookies.Add(new HttpCookie("system_message", string.Format(MessageUI.CreateSuccess, FormUI.PaymentMethod))); if (!Url.IsLocalUrl(returnUrl) || returnUrl.Length <= 1 || !returnUrl.StartsWith("/") || returnUrl.StartsWith("//") || returnUrl.StartsWith("/\\")) { action = RedirectToAction("Index"); } else { action = Redirect(returnUrl); } } catch (Exception ex) { LogText.Log(string.Concat("PaymentMethod.Create: ", ex.Message)); ModelState.AddModelError("", ex.Message); return(View(model)); } return(action); }
public async Task <ActionResult <PaymentMethodDetail_PaymentMethodDTO> > Create([FromBody] PaymentMethodDetail_PaymentMethodDTO PaymentMethodDetail_PaymentMethodDTO) { if (!ModelState.IsValid) { throw new MessageException(ModelState); } PaymentMethod PaymentMethod = ConvertDTOToEntity(PaymentMethodDetail_PaymentMethodDTO); PaymentMethod = await PaymentMethodService.Create(PaymentMethod); PaymentMethodDetail_PaymentMethodDTO = new PaymentMethodDetail_PaymentMethodDTO(PaymentMethod); if (PaymentMethod.IsValidated) { return(PaymentMethodDetail_PaymentMethodDTO); } else { return(BadRequest(PaymentMethodDetail_PaymentMethodDTO)); } }