public ActionResult Create(TaxpayerRecipient item) { if (!string.IsNullOrEmpty (item.Id)) { var entity = TaxpayerRecipient.TryFind (item.Id); if (entity != null) { ModelState.AddModelError ("", Resources.TaxpayerRecipientAlreadyExists); } } if (!item.HasAddress) { ModelState.Where (x => x.Key.StartsWith ("Address.")).ToList ().ForEach (x => x.Value.Errors.Clear ()); item.Address = null; } if (!ModelState.IsValid) { return PartialView ("_Create", item); } item.Id = item.Id.ToUpper ().Trim (); item.Name = item.Name.Trim (); item.Email = item.Email.Trim (); using (var scope = new TransactionScope ()) { if (item.HasAddress) { item.Address.Create (); } item.CreateAndFlush (); } return PartialView ("_CreateSuccesful", item); }
public ActionResult Create (TaxpayerRecipient item) { if (!string.IsNullOrEmpty (item.Id)) { var entity = TaxpayerRecipient.TryFind (item.Id); if (entity != null) { ModelState.AddModelError ("", Resources.TaxpayerRecipientAlreadyExists); } } if (!ModelState.IsValid) { return PartialView ("_Create", item); } item.Id = item.Id.ToUpper ().Trim (); item.Name = item.Name?.Trim (); item.Email = item.Email.Trim (); if (string.IsNullOrWhiteSpace (item.Name)) { item.Name = null; } using (var scope = new TransactionScope ()) { item.CreateAndFlush (); } return PartialView ("_CreateSuccesful", item); }
public ActionResult DeleteConfirmed (string id) { var item = TaxpayerRecipient.Find (id); try { using (var scope = new TransactionScope ()) { item.DeleteAndFlush (); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine (ex); return PartialView ("DeleteUnsuccessful"); } return PartialView ("_DeleteSuccesful", item); }
public ActionResult Edit (TaxpayerRecipient item) { if (!ModelState.IsValid) { return PartialView ("_Edit", item); } var entity = TaxpayerRecipient.Find (item.Id); entity.Name = item.Name?.Trim (); entity.Email = item.Email.Trim (); if (string.IsNullOrWhiteSpace (item.Name)) { item.Name = null; } using (var scope = new TransactionScope ()) { entity.UpdateAndFlush (); } return PartialView ("_Refresh"); }
public ActionResult AddTaxpayer(int id, string value) { var item = Customer.TryFind(id); var taxpayer = TaxpayerRecipient.TryFind(value); if (item == null) { Response.StatusCode = 400; return(Content(Resources.CustomerNotFound)); } if (taxpayer == null) { Response.StatusCode = 400; return(Content(Resources.TaxpayerRecipientNotFound)); } using (var scope = new TransactionScope()) { item.Taxpayers.Add(taxpayer); item.Update(); } return(Json(new { id = id, result = true })); }
public ActionResult Edit(TaxpayerRecipient item) { if (!item.HasAddress) { ModelState.Where (x => x.Key.StartsWith ("Address.")).ToList ().ForEach (x => x.Value.Errors.Clear ()); item.Address = null; } if (!ModelState.IsValid) { return PartialView ("_Edit", item); } var entity = TaxpayerRecipient.Find (item.Id); var address = entity.Address; entity.HasAddress = (address != null); entity.Name = item.Name.Trim (); entity.Email = item.Email.Trim (); using (var scope = new TransactionScope ()) { if (item.HasAddress) { entity.Address = item.Address; entity.Address.Create (); } else { entity.Address = null; } entity.UpdateAndFlush (); } if (address != null) { try { using (var scope = new TransactionScope ()) { address.DeleteAndFlush (); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine (ex); } } return PartialView ("_Refresh"); }
public ActionResult Delete (string id) { var item = TaxpayerRecipient.Find (id); return PartialView ("_Delete", item); }
public ActionResult Edit (string id) { var item = TaxpayerRecipient.Find (id); return PartialView ("_Edit", item); }