public dynamic Put(string enrollmentNumber) { Enrollment enrollment = _enrollmentService.List().SingleOrDefault(x => x.ExternalId == enrollmentNumber); if (enrollment == null) { return(new BadRequestObjectResult(new { messages = new List <string> { onboarding.Resources.Messages.EnrollmentLinkIsNotValid } })); } if (!enrollment.IsDeadlineValid()) { return(new BadRequestObjectResult(new { messages = new List <string> { onboarding.Resources.Messages.OnboardingExpired } })); } using (HttpClient client = new HttpClient()) { RepresentativeViewModel representative = enrollment.FinanceData.Representative is RepresentativeCompany ? (RepresentativeViewModel)_mapper.Map <RepresentativeCompanyViewModel>(enrollment.FinanceData.Representative) : (RepresentativeViewModel)_mapper.Map <RepresentativePersonViewModel>(enrollment.FinanceData.Representative); representative.Discriminator = enrollment.FinanceData.Representative.GetType().Name; Invoice invoice = new Invoice { InvoiceNumber = "", Value = enrollment.FinanceData.Plan.Value, DueDate = "25/12/2018", Items = new List <Item>() { new Item { EnrollmentNumber = enrollmentNumber } }, Representative = representative }; StringContent stringContent = new StringContent(JsonConvert.SerializeObject(invoice), Encoding.UTF8, "application/json"); HttpResponseMessage httpResponseMessage = client.PostAsync(_configuration["FINANCE_HOST"] + "/api/invoices/", stringContent).Result; if (httpResponseMessage.StatusCode != HttpStatusCode.OK) { return(JsonConvert.DeserializeObject(httpResponseMessage.Content.ReadAsStringAsync().Result)); } dynamic resultObj = JsonConvert.DeserializeObject(httpResponseMessage.Content.ReadAsStringAsync().Result); enrollment.InvoiceId = resultObj.data.id; _context.Enrollments.Update(enrollment); _context.SaveChanges(); return(resultObj); } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var obj = JObject.Load(reader); RepresentativeViewModel representative; if (obj["discriminator"] != null && obj["discriminator"].ToString() == "RepresentativePerson") { representative = new RepresentativePersonViewModel(); } else if (obj["discriminator"] != null && obj["discriminator"].ToString() == "RepresentativeCompany") { representative = new RepresentativeCompanyViewModel(); } else { representative = new RepresentativeViewModel(); } serializer.Populate(obj.CreateReader(), representative); return(representative); }
public ActionResult CreateContract(ContractDistributorVM model, [Bind(Prefix = "ContractViewModel")] ContractViewModel con, [Bind(Prefix = "DistributorViewModel")] DistributorViewModel dis, [Bind(Prefix = "RepresentativeViewModel")] RepresentativeViewModel rep) { isAdminLogged(); logger.Info("Start controller to create contract..."); var user = Session["admin"] as Account; bool result; var _con = new Contract(); _con.area = con.area; _con.beginDate = con.beginDate; _con.commission = con.commission; _con.disType = con.disType; _con.expiredDate = con.expiredDate; _con.maxDebt = con.maxDebt; _con.minOrderTotalValue = con.minOrderTotalValue; _con.note = con.note; _con.staff = staff_Service.GetByAccount(user.UserName).idStaff; if (rep.idRepresentative == 0) // Create contract for old distributor { Representative _rep = new Representative { idRepresentative = rep_Service.GenerateRepresentativeId(), name = rep.name, title = rep.title, phone = rep.phone, email = rep.email, Distributor = dis.idDistributor }; _con.Representative1 = _rep; _con.distributor = dis.idDistributor; result = con_Service.CreateContract(_con, false); } else // Create contract for potential distributor { Distributor _dis = new Distributor { idDistributor = dis_Service.GenerateDistributorId(), name = dis.name, address = dis.address, Email = dis.Email, phone = dis.phone, createdDate = DateTime.Now, updatedDate = DateTime.Now, debt = 0, status = true }; _con.Distributor1 = _dis; // _dis.idDistributor; _con.representative = rep.idRepresentative; result = con_Service.CreateContract(_con, true); //pDis_Service.UpdateStatus(dis.idDistributor, 5, "Đã tạo hợp đồng"); } if (result == true) { TempData["success"] = "Thành công"; model = new ContractDistributorVM(); logger.Info("End: Successful...."); } else { TempData["fail"] = "Thất bại"; logger.Info("End: Unsuccessful...."); } return(RedirectToAction("CreateContract")); }