コード例 #1
0
        public ActionResult Edit(DecisionViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var f = Request.Files["Document"];
                    if (f != null && f.ContentLength > 0)
                    {
                        string pic        = System.IO.Path.GetFileName(f.FileName);//System.IO.Path.GetFileName(f.FileName);
                        var    avatarpath = "/Uploads/Lichsuquyetdinhs";
                        string path       = System.IO.Path.Combine(Server.MapPath(avatarpath), pic);
                        // file is uploaded
                        f.SaveAs(path);
                        using (MemoryStream ms = new MemoryStream())
                        {
                            f.InputStream.CopyTo(ms);
                            byte[] array = ms.GetBuffer();
                        }
                        model.Document = string.Join("/", avatarpath, pic);
                    }

                    service.Update(model);
                    service.Save();
                    return(RedirectToAction("Index", "Decision", new { employeeId = model.EmployeeId }));
                }

                var employees = employee.GetEmployeeSelectListItems().Select(x => new {
                    Id   = x.Id,
                    Name = x.Id + " - " + x.FirstName + " " + x.LastName
                }).ToList();
                ViewBag.Employees = new SelectList(employees, "Id", "Name");

                return(View(model));
            }
            catch
            {
                return(View());
            }
        }