Exemplo n.º 1
0
        public ActionResult Create(RequestCrane rc)
        {
            if (rc.Request.ApproverEmployeeId == 0)
            {
                ViewBag.ErrorMessage = "Веберите руководителя, который подпишет заявку!";
                return View(rc);
            }

            try
            {
                rc.Request.Status = 0;
                rc.Request.UserLogin = User.Identity.Name;
                rc.Request.UserFio = AccountManager.GetUserDisplayName(User.Identity.Name);
                rc.Request.PublishDate = DateTime.Now;
                rc.Request.IsDeleted = false;

                if (rc.Request.CustomerId == 0)
                    rc.Request.CustomerId = null;

                if (Utils.AccountManager.IsApprover(User.Identity.Name).Item2)
                {
                    rc.Request.Status = 1;
                    rc.Request.ApproveDate = DateTime.Now;
                    rc.Request.ApproverLogin = User.Identity.Name;
                    rc.Request.ApproverFio = Utils.AccountManager.GetUserDisplayName(User.Identity.Name);

                    RequestEvent re = new RequestEvent();
                    re.Status = 1;
                    re.EventDate = DateTime.Now;
                    rc.Request.RequestEvents.Add(re);
                }

                _db.RequestCranes.Add(rc);
                _db.SaveChanges();

                return View("Published", rc.Request.RequestId);
            }
            catch (DbEntityValidationException dbEx)
            {

                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        //TODO: Попытка удалить запись, у которой ExpDate истек
                    }
                }

                ViewBag.ErrMessage = "Ошибка при создании записи";
                ViewBag.BackController = "Home";
                return View("Error");
            }
        }
Exemplo n.º 2
0
 //
 // GET: /Crane/Create
 public ActionResult Create()
 {
     var rc = new RequestCrane();
     rc.RequestCraneSlingers.Add(new RequestCraneSlinger());
     return View(rc);
 }
Exemplo n.º 3
0
        public ActionResult Edit(RequestCrane rc)
        {
            try
            {
                var model = _db.RequestCranes.Single(m => m.RequestId == rc.RequestId);

                model.Request.RequestDate = rc.Request.RequestDate;
                model.LicenceNumber = rc.LicenceNumber;
                model.WorkPlace = rc.WorkPlace;
                model.WorkObject = rc.WorkObject;
                model.WorkType = rc.WorkType;
                model.CraneType = rc.CraneType;
                model.PowerLineExists = rc.PowerLineExists;
                model.PowerPermission = rc.PowerPermission;
                model.Responsible = rc.Responsible;
                model.ProjectExists = rc.ProjectExists;
                model.ResponsibleOrder = rc.ResponsibleOrder;
                model.CustomerName = rc.CustomerName;
                model.Request.ApproverEmployeeId = rc.Request.ApproverEmployeeId;

                if (rc.Request.CustomerId == 0)
                    rc.Request.CustomerId = null;
                model.Request.CustomerId = rc.Request.CustomerId;

                if (model.Request.Status == 3 && User.Identity.Name.ToLower() == model.Request.UserLogin.ToLower())
                {
                    model.Request.Status = 0;
                    RequestEvent re = new RequestEvent();
                    re.Status = 0;
                    re.Message = String.Empty;
                    re.EventDate = DateTime.Now;
                    model.Request.RequestEvents.Add(re);
                }

                var modelSlingers = model.RequestCraneSlingers;
                var respSlingers = rc.RequestCraneSlingers;

                foreach (var modelSlinger in modelSlingers)
                {
                    //Существует ли такой груз в респонсе
                    bool slingerExistInResponse = false;

                    foreach (var respSlinger in respSlingers)
                    {
                        //Если обновление груза
                        if (respSlinger.SlingerId == modelSlinger.SlingerId)
                        {
                            modelSlinger.Office = respSlinger.Office;
                            modelSlinger.FIO = respSlinger.FIO;
                            modelSlinger.CertificateNumber = respSlinger.CertificateNumber;
                            modelSlinger.DateKnowledge = respSlinger.DateKnowledge;

                            slingerExistInResponse = true;
                        }
                    }

                    if (slingerExistInResponse == false)
                        modelSlinger.IsDeleted = true;
                }

                //Добавляем все новые грузы, т.е те, у которых CargoId == 0
                foreach (var respSlinger in respSlingers)
                    if (respSlinger.SlingerId == 0)
                        modelSlingers.Add(respSlinger);

                _db.SaveChanges();

                return RedirectToAction("Index", "Home");
            }
            catch
            {
                ViewBag.ErrMessage = "Ошибка при редактировании записи";
                ViewBag.BackController = "Home";
                return View("Error");
            }
        }