public ActionResult Edit(Task task)
        {
            if (ModelState.IsValid)
            {
                task.updateDate      = DateTime.Now;
                db.Entry(task).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Edit", "InstructionWorks", new { id = task.workID }));
            }

            return(View(task));
        }
        public ActionResult Edit(Department department)
        {
            if (ModelState.IsValid)
            {
                department.updateDate      = DateTime.Now;
                department.companyID       = (int)db.Users.Find(department.createUser).companyID;
                db.Entry(department).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(department));
        }
Esempio n. 3
0
 public ActionResult Edit(User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.companyID    = new SelectList(db.Companies, "ID", "name", user.companyID);
     ViewBag.departmentID = new SelectList(db.Departments, "ID", "name", user.departmentID);
     ViewBag.positionID   = new SelectList(db.Positions, "ID", "name", user.positionID);
     ViewBag.createUser   = new SelectList(db.Users, "ID", "name", user.createUser);
     return(View(user));
 }
        public ActionResult Edit(PurposeEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                var document = db.Documents.Find(model.id);
                document.updateDate      = DateTime.Now;
                document.documentText    = model.document_text;
                db.Entry(document).State = EntityState.Modified;
                if (model.isNewVersion)
                {
                    var hist_document = new HistDocument(document);
                    hist_document.changeReason = model.changeReason;
                    document.version++;
                    db.HistDocuments.Add(hist_document);
                    db.Entry(document).State = EntityState.Modified;
                }

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Esempio n. 5
0
        public ActionResult Edit(CompanyViewModel company, HttpPostedFileBase logoImage)
        {
            if (ModelState.IsValid)
            {
                Company comp = db.Companies.Include(c => c.Rules).FirstOrDefault(c => c.ID == company.ID);
                comp.Rules.Clear();

                db.Entry(comp).State = EntityState.Modified;

                var imageGUID = Guid.NewGuid();
                if (logoImage != null)
                {
                    string imageUrl = imageGUID +
                                      Path.GetExtension(logoImage.FileName);
                    string filePath = Path.Combine(
                        Server.MapPath("~/Uploads/CompanyLogos"),
                        imageGUID + Path.GetExtension(logoImage.FileName
                                                      ));

                    if (logoImage.ContentLength > 102400)
                    {
                        MemoryStream target = new MemoryStream();
                        logoImage.InputStream.CopyTo(target);
                        var resizedImage = new ImageResizer(target.ToArray());
                        resizedImage.Resize(400, 200, false, ImageEncoding.Jpg90);
                        resizedImage.SaveToFile(filePath);
                    }
                    else
                    {
                        logoImage.SaveAs(filePath);
                    }

                    var      images = Directory.GetFiles(Server.MapPath("~/Uploads/CompanyLogos"));
                    FileInfo old    = new FileInfo(Server.MapPath("~/Uploads/CompanyLogos") + "\\" + company.logo);
                    if (images.Contains(old.FullName))
                    {
                        filePath = logoImage.FileName;
                        System.IO.File.Delete(Path.Combine(Server.MapPath("~/Uploads/CompanyLogos"), company.logo));
                        company.logo = filePath;
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(company.filename))
                    {
                        var      images = Directory.GetFiles(Server.MapPath("~/Uploads/CompanyLogos"));
                        FileInfo old    = new FileInfo(Server.MapPath("~/Uploads/CompanyLogos") + "\\" + company.logo);
                        if (images.Contains(old.FullName))
                        {
                            System.IO.File.Delete(Path.Combine(Server.MapPath("~/Uploads/CompanyLogos"), company.logo));
                            company.logo = "";
                        }
                    }
                }

                comp.name        = company.name;
                comp.companyText = company.companyText;
                comp.description = company.description;
                comp.email       = company.email;

                if (logoImage != null)
                {
                    comp.logo = imageGUID + Path.GetExtension(logoImage.FileName);
                }
                else
                {
                    comp.logo = "";
                }

                comp.status = company.status;
                if (company.rulesCompany != null)
                {
                    foreach (int r in company.rulesCompany)
                    {
                        var rule = db.Rules.Find(r);
                        comp.Rules.Add(rule);
                    }
                }
                db.Entry(comp).State = EntityState.Modified;

                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.rulesCompany = db.Rules.ToSelectListItems(r => r.code + " - " + r.name, r => r.ID.ToString(), rl => company.rulesCompany.Contains(rl.ID));
            return(View(company));
        }