public ActionResult EditChildPart(ChildPartsModel model) { using (var db = new WebAppDbContext()) { using (var transaction = db.Database.BeginTransaction()) { PartsViewModels vm = new PartsViewModels(); try { if (!ModelState.IsValid) { Alert("Their is something went wrong!!!", NotificationType.error); return(Json(model, JsonRequestBehavior.AllowGet)); } if (model.ParentPartId != 0 && model.ChildPartId != 0) { var obj = new tbl_ChildParts() { ParentPartId = model.ParentPartId, ChildPartId = model.ChildPartId, Qty = model.Qty, }; db.Entry(obj).State = EntityState.Modified; } db.SaveChanges(); transaction.Commit(); int?parentPartId = model.ParentPartId; if (parentPartId != 0) { vm = GetData(parentPartId); } // Alert("Data Saved Sucessfully!!!", NotificationType.success); return(Json(vm.ChildPartsModel_list, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { transaction.Rollback(); Exception(ex); Alert("Their is something went wrong!!!", NotificationType.error); return(Json(vm)); } } } }
public ActionResult AddChildPart(tbl_ChildParts model) { string actionName = "AddChildPart"; _logger.Log(LogLevel.Trace, actionName + " :: started."); using (var db = new WebAppDbContext()) { using (var transaction = db.Database.BeginTransaction()) { PartsViewModels vm = new PartsViewModels(); try { if (!ModelState.IsValid) { _logger.Log(LogLevel.Trace, actionName + " :: ended."); Alert("Their is something went wrong!!!", NotificationType.error); return(Json(model, JsonRequestBehavior.AllowGet)); } if (model.ParentPartId != 0 && model.ChildPartId != 0) { db.tbl_ChildParts.Add(model); db.SaveChanges(); transaction.Commit(); } int?parentPartId = model.ParentPartId; if (parentPartId != 0) { vm = GetData(parentPartId); } _logger.Log(LogLevel.Trace, actionName + " :: ended."); // Alert("Data Saved Sucessfully!!!", NotificationType.success); return(Json(vm.ChildPartsModel_list, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { _logger.Log(LogLevel.Error, actionName + " EXCEPTION :: " + ex.ToString() + " INNER EXCEPTION :: " + ex.InnerException?.ToString()); transaction.Rollback(); Exception(ex); Alert("Their is something went wrong!!!", NotificationType.error); return(Json(vm)); } } } }