Beispiel #1
0
        public ActionResult UpdateFault(Machine m, int repairmanId)
        {
            try
            {
                if (m.Fault != null)
                {
                    MachineDao mDao = new MachineDao();
                    UserDao    uDao = new UserDao();

                    m.FaultUser = uDao.GetByLogin(User.Identity.Name);
                    m.Repairman = uDao.GetById(repairmanId);
                    m.FaultDate = DateTime.Today;
                    m.Status    = "Poškozený";

                    mDao.Update(m);

                    TempData["succes"] = "Závada na stroji " + m.Name + " přidána.";
                }
                else
                {
                    TempData["warning"] = "Nebyl vyplněn popis závady.";
                    return(View("EditFault", m));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ActionResult Update(Machine mach, HttpPostedFileBase picture, string status)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (picture != null)
                    {
                        ImageClass.ImageMethod(picture, "Machine", out string bigImageName, out string smallImageName, out string tempData);

                        if (tempData != null)
                        {
                            TempData["warning"] = tempData;
                        }

                        if (mach.SmallImageName != null)
                        {
                            System.IO.File.Delete(Server.MapPath("~/Uploads/Machine/" + mach.SmallImageName));
                        }
                        if (mach.BigImageName != null)
                        {
                            System.IO.File.Delete(Server.MapPath("~/Uploads/Machine/" + mach.BigImageName));
                        }

                        mach.BigImageName   = bigImageName;
                        mach.SmallImageName = smallImageName;
                    }
                    MachineDao mDao = new MachineDao();
                    UserDao    uDao = new UserDao();

                    mach.Repairman = uDao.GetByLogin(User.Identity.Name);
                    mach.Status    = status;

                    if (mach.Status == "Poškozený")
                    {
                        mach.FaultUser = uDao.GetByLogin(User.Identity.Name);
                        mach.FaultDate = DateTime.Today;
                    }

                    mDao.Update(mach);
                }
                else
                {
                    return(View("Edit", mach));
                }
                if (TempData["warning"] == null)
                {
                    TempData["succes"] = "Úprava stroje " + mach.Name + " proběhla úspěšně.";
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
            return(RedirectToAction("Index"));
        }