public ActionResult GridViewWorksUpdate(Database.Work item) { var model = dbWorks.Works; if (ModelState.IsValid) { try { var modelItem = model.FirstOrDefault(it => it.id == item.id); if (modelItem != null) { UpdateModel(modelItem); dbWorks.SaveChanges(); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(PartialView("_GridViewWorks", BLObject.ObjectWorks.GetObjectWorkModel())); }
public ActionResult WorkerWorksPartialAddNew(Database.Work item) { var model = dbWorks.Works; if (ModelState.IsValid) { try { if (item.unit_price_worker == null) { item.unit_price_worker = item.unit_price; } model.Add(item); dbWorks.SaveChanges(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(PartialView("_WorkerWorksPartial", BLWorkers.Works.GetWorkerWorksModel())); }
public ActionResult WorkerWorksPartialUpdate(Database.Work item) { var model = dbWorks.Works; if (ModelState.IsValid) { try { if (item.is_paid == 1) { var modelPayments = dbWorkerPayment.WorkerPayments; Database.WorkerPayment workerPayment = new Database.WorkerPayment { // payment_date = DateTime.Now, worker_id = MySession.Current.WorkerId, work_id = item.id, amount = Convert.ToDecimal(item.unit_price_worker) * Convert.ToDecimal(item.surface_work), userId = MySession.Current.UserGuid }; modelPayments.Add(workerPayment); dbWorkerPayment.SaveChanges(); } else { var payments = dbWorkerPayment.WorkerPayments; var payment = dbWorkerPayment.WorkerPayments.FirstOrDefault(x => x.work_id == item.id); if (payment != null) { payments.Remove(payment); } dbWorkerPayment.SaveChanges(); } // var modelItem = model.FirstOrDefault(it => it.id == item.id); if (modelItem != null) { UpdateModel(modelItem); dbWorks.SaveChanges(); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(PartialView("_WorkerWorksPartial", BLWorkers.Works.GetWorkerWorksModel())); }
public ActionResult GridViewWorksAddNew(Database.Work item) { var model = dbWorks.Works; if (ModelState.IsValid) { try { item.object_id = MySession.Current.ObjectId; if (item.date_end == null && item.date_start == null) { item.date_start = DateTime.Now; item.date_end = DateTime.Now; } if (item.surface_work == null) { item.surface_work = 0; } if (item.unit_price == null) { item.unit_price = 0; } model.Add(item); dbWorks.SaveChanges(); } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { ViewData["EditError"] = "Please, correct all errors."; } return(PartialView("_GridViewWorks", BLObject.ObjectWorks.GetObjectWorkModel())); }