// GET: Incomings/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EditIncomingModel CurrentEditIncomingModel = new EditIncomingModel(db.Incomings.Find(id)); if (CurrentEditIncomingModel.EditedIncoming == null) { return(HttpNotFound()); } return(View(CurrentEditIncomingModel)); }
public ActionResult Edit(EditIncomingModel incoming, int?CounterpartyTypeDb) { if (ModelState.IsValid) { if (CounterpartyTypeDb == 0) // dbOrest { var orestClient = OrestDb.klt.Find(incoming.EditedIncoming.CounterpartyId); Counterparty tempClient = new Counterparty(); tempClient.Name = orestClient.name; tempClient.AccountNumber = orestClient.chet; tempClient.ActualAddress = orestClient.adft; tempClient.BankMFO = orestClient.mfob; tempClient.BankName = orestClient.bank; tempClient.CodVATPayer = orestClient.knds; tempClient.VATCertificateNumber = orestClient.snds; tempClient.Comment = orestClient.comt; tempClient.ContactPerson = orestClient.cont; tempClient.Discount = orestClient.per; tempClient.EDRPO = orestClient.okpo; tempClient.FullName = orestClient.full; tempClient.IdOrest = orestClient.id; tempClient.VATPayer = !Convert.ToBoolean(orestClient.nds); db.Counterparties.Add(tempClient); incoming.EditedIncoming.Counterparty = tempClient; db.Entry(incoming.EditedIncoming).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } else { incoming.EditedIncoming.Counterparty = db.Counterparties.Find(incoming.EditedIncoming.CounterpartyId); db.Entry(incoming.EditedIncoming).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } //incoming.EditedIncoming.Counterparty = db.Counterparties.Find(incoming.EditedIncoming.CounterpartyId); //if (incoming.EditedIncoming.Counterparty == null) //{ // //var id = incoming.EditedIncoming.CounterpartyId; // var orestClient = OrestDb.klt.Find(incoming.EditedIncoming.CounterpartyId); // Counterparty tempClient = new Counterparty(); // tempClient.Name = orestClient.name; // tempClient.AccountNumber = orestClient.chet; // tempClient.ActualAddress = orestClient.adft; // tempClient.BankMFO = orestClient.mfob; // tempClient.BankName = orestClient.bank; // tempClient.CodVATPayer = orestClient.knds; // tempClient.Comment = orestClient.comt; // tempClient.ContactPerson = orestClient.cont; // tempClient.Discount = orestClient.per; // tempClient.EDRPO = orestClient.okpo; // tempClient.FullName = orestClient.full; // tempClient.IdOrest = orestClient.id; // db.Counterparties.Add(tempClient); // incoming.EditedIncoming.Counterparty = tempClient; // db.Entry(incoming.EditedIncoming).State = EntityState.Modified; // db.SaveChanges(); // return RedirectToAction("Index"); //} //else //{ // db.Entry(incoming.EditedIncoming).State = EntityState.Modified; // db.SaveChanges(); // return RedirectToAction("Index"); //} } ViewBag.BankId = new SelectList(db.Banks, "Id", "BankName", incoming.EditedIncoming.Bank); ViewBag.CounterpartyId = new SelectList(db.Counterparties, "Id", "Name", incoming.EditedIncoming.CounterpartyId); ViewBag.IncomingCategoryId = new SelectList(db.IncomingCategorys, "Id", "IncomingCategoryName", incoming.EditedIncoming.IncomingCategoryId); ViewBag.WayOfPaymentId = new SelectList(db.WayOfPayments, "Id", "WayOfPaymentName", incoming.EditedIncoming.WayOfPaymentId); ViewBag.IncomingTypeId = new SelectList(db.IncomingTypes, "Id", "TypeName", incoming.EditedIncoming.IncomingTypeId); ViewBag.WayOfPaymentId = new SelectList(db.WayOfPayments, "Id", "WayOfPaymentName", incoming.EditedIncoming.WayOfPaymentId); return(View(incoming)); }