Exemplo n.º 1
0
        public async Task <ActionResult> Edit([Bind(Include = "WorkOrderId,CustomerId,OrderDateTime,TargetDateTime,DropDeadDateTime,Description,WorkOrderStatus,CertificationRequirements,CurrentWorkerId,ReworkNotes")] WorkOrder workOrder, string command)
        {
            if (ModelState.IsValid)
            {
                // Populate Parts and Labors.
                workOrder.Parts =
                    _applicationDbContext.Parts.Where(p => p.WorkOrderId == workOrder.WorkOrderId).ToList();
                workOrder.Labors =
                    _applicationDbContext.Labors.Where(l => l.WorkOrderId == workOrder.WorkOrderId).ToList();

                var promotionResult = new PromotionResult();

                if (command == "Save")
                {
                    promotionResult.Success = true;
                }
                else if (command == "Claim")
                {
                    promotionResult = workOrder.ClaimWorkListItem(User.Identity.GetUserId());
                }
                else
                {
                    promotionResult = workOrder.PromoteWorkListItem(command);
                }

                if (!promotionResult.Success)
                {
                    TempData["MessageToClient"] = promotionResult.Message;
                }

                _applicationDbContext.Entry(workOrder).State = EntityState.Modified;
                await _applicationDbContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(workOrder));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> Edit([Bind(Include = "WorkOrderId,CustomerId,OrderDateTime,TargetDateTime,DropDeadDateTime,Description,WorkOrderStatus,CertificationRequirements,CurrentWorkerId,ReworkNotes,RowVersion")] WorkOrder workOrder, string command)
        {
            if (ModelState.IsValid)
            {
                //Populate Parts and Labors
                workOrder.Parts  = _applicationDbContext.Parts.Where(p => p.WorkOrderId == workOrder.WorkOrderId).ToList();
                workOrder.Labors = _applicationDbContext.Labors.Where(p => p.WorkOrderId == workOrder.WorkOrderId).ToList();

                PromotionResult promotionResult = new PromotionResult();

                if (command == "Save")
                {
                    promotionResult.Success = true;
                }
                else if (command == "Claim")
                {
                    promotionResult = workOrder.ClaimWorkListItem(User.Identity.GetUserId());
                }
                else if (command == "Relinquish")
                {
                    promotionResult = workOrder.RelinquishWorkListItem();
                }
                else
                {
                    promotionResult = workOrder.PromoteWorkListItem(command);
                }

                if (!promotionResult.Success)
                {
                    TempData["MessageToClient"] = promotionResult.Message;
                }

                //try
                //{
                //    var zero = 0;
                //    var test = 1 / zero;
                //}
                //catch (Exception ex)
                //{

                //    Log4NetHelper.Log(null, LogLevel.ERROR, "WorkOrders", workOrder.WorkOrderId, User.Identity.Name, ex);
                //}

                _applicationDbContext.Entry(workOrder).State = EntityState.Modified;
                try
                {
                    await _applicationDbContext.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (command == "Claim")
                    {
                        TempData["MessageToClient"] = String.Format("Someone else has claimed work order {0} since you retrieved it.", workOrder.WorkOrderId);
                    }
                    else
                    {
                        TempData["MessageToClient"] = String.Format("Someone else has modified work order {0} since you retrieved it.", workOrder.WorkOrderId);
                    }

                    return(RedirectToAction("Index", "WorkList"));
                }



                //Audit Trail
                Log4NetHelper.Log(promotionResult.Message, LogLevel.INFO, workOrder.EntityFormalNamePlural, workOrder.Id, User.Identity.Name, null);

                if (command == "Claim" && promotionResult.Success)
                {
                    return(RedirectToAction("Edit", workOrder.WorkOrderId));
                }


                return(RedirectToAction("Index", "WorkList"));
            }
            return(View(workOrder));
        }
        public async Task <ActionResult> Edit([Bind(Include = "WorkOrderId,CustomerId,OrderDateTime,TargetDateTime,DropDeadDateTime,Description,WorkOrderStatus,CertificationRequirements,CurrentWorkerId,ReworkNotes,RowVersion")] WorkOrder workOrder, string command)
        {
            if (ModelState.IsValid)
            {
                workOrder.Parts  = db.Parts.Where(p => p.WorkOrderId == workOrder.WorkOrderId).ToList();
                workOrder.Labors = db.Labors.Where(l => l.WorkOrderId == workOrder.WorkOrderId).ToList();

                PromotionResult pr = new PromotionResult();

                if (command == "Save")
                {
                    pr.Success = true;
                    pr.Message = String.Format("Changes to work order {0} have been successfully saved.", workOrder.Id);
                    Log4NetHelper.Log(pr.Message, LogLevel.INFO, workOrder.EntityFormalNamePlural, workOrder.Id, User.Identity.Name, null);
                }
                else if (command == "Claim")
                {
                    pr = workOrder.ClaimWorkListItem(User.Identity.GetUserId());
                }
                else if (command == "Relinquish")
                {
                    pr = workOrder.RelinquishWorkListItem();
                }
                else
                {
                    pr = workOrder.PromoteWorkListItem(command);
                }

                if (!pr.Success)
                {
                    TempData["MessageToClient"] = pr.Message;
                }

                //try
                //{
                //    var zero = 0;
                //    var test = 1 / zero;
                //}
                //catch (Exception ex)
                //{
                //    Log4NetHelper.Log(null, LogLevel.ERROR, "WorkOrders", workOrder.WorkOrderId, User.Identity.Name, ex);
                //}

                //Now is handle by the ClaimWorkOrder method
                //workOrder.CurrentWorkerId = User.Identity.GetUserId();
                db.Entry(workOrder).State = EntityState.Modified;
                try
                {
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    if (command == "Claim")
                    {
                        TempData["MessageToClient"] = String.Format("Someone else has claimed work order {0} since you retrieve it.", workOrder.WorkOrderId);
                    }
                    else
                    {
                        TempData["MessageToClient"] = String.Format("Someone else has modified work order {0} since you retrieve it.", workOrder.WorkOrderId);
                    }
                    return(RedirectToAction("Index", "WorkList"));
                }
                Log4NetHelper.Log(pr.Message, LogLevel.INFO, workOrder.EntityFormalNamePlural, workOrder.Id, User.Identity.Name, null);
                if (command == "Claim" && pr.Success)
                {
                    return(RedirectToAction("Edit", workOrder.WorkOrderId));
                }

                return(RedirectToAction("Index", "WorkList"));
            }
            //ViewBag.CurrentWorkerId = new SelectList(db.ApplicationUsers, "Id", "FirstName", workOrder.CurrentWorkerId);
            //ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "AccountNumber", workOrder.CustomerId);
            return(View(workOrder));
        }