Exemple #1
0
        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()));
        }
Exemple #2
0
        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()));
        }
Exemple #3
0
        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()));
        }
Exemple #4
0
        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()));
        }