public ActionResult Index([FromBody] TalentCreditCardEditVM modelVM) { try { var curUser = accountUtil.GetCurrentUser(User); Talent model = TalentService.GetByID(modelVM.id); if (model == null || !model.UserID.Equals(curUser.ID)) { throw new Exception("Талант не найден"); } if (ModelState.IsValid) { model.CreditCardNumber = modelVM.credit_card_number.Replace(" ", ""); model.CreditCardHolder = modelVM.credit_card_holder; if (!string.IsNullOrWhiteSpace(modelVM.credit_card_expire)) { string[] tmp = modelVM.credit_card_expire.Split('/'); string monthString = tmp[0]; string yearString = tmp[1]; int month = int.Parse(monthString); int year = int.Parse(yearString) + 2000; DateTime creditCardExpireTmp = new DateTime(year, month, 1); //day does not play any role if (!ExpiresIn3Months(creditCardExpireTmp)) { model.CreditCardExpire = creditCardExpireTmp; TalentService.Update(model, curUser.ID); return(Ok()); } else { throw new Exception("Срок годности карты истекает менее чем через 3 месяца"); } //ModelState.AddModelError("", "Срок годности карты истекает менее чем через 3 месяца"); } else { throw new Exception("Некорректный срок годности"); } //ModelState.AddModelError("", "Некорректный срок годности"); } else { throw new Exception("Указаны некорректные данные"); } } catch (Exception ex) { return(CustomBadRequest(ex)); } }
public ActionResult <TalentCreditCardEditVM> Index() { try { var curUser = accountUtil.GetCurrentUser(User); Talent model = TalentService.GetByUserID(curUser.ID); if (model == null) { throw new Exception("Талант не найден"); } TalentCreditCardEditVM modelVM = new TalentCreditCardEditVM(model); return(Ok(modelVM)); } catch (Exception ex) { return(CustomBadRequest(ex)); } }