コード例 #1
0
        public ActionResult Edit(Teaching teaching)
        {
            if (ModelState.IsValid)
            {
                db.Entry(teaching).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(teaching);
        }
コード例 #2
0
        public ActionResult LecturerUploadFile(HttpPostedFileBase selectedFile, string rename)
        {
            try
            {
                if (selectedFile != null && selectedFile.ContentLength > 0)
                {
                    string guid = Guid.NewGuid().ToString() + Path.GetExtension(selectedFile.FileName);

                    //var fileName = selectedFile.FileName;
                    //var filePath = Path.Combine(Server.MapPath("~/LecturerUploadedFiles/"), fileName);

                    var filePath = Path.Combine(Server.MapPath("~/LecturerUploadedFiles/"), guid);

                    //if (!string.IsNullOrEmpty(rename))
                    //{
                    //    filePath = Path.Combine(Server.MapPath("~/LecturerUploadedFiles/"), rename + Path.GetExtension(selectedFile.FileName));
                    //}

                    selectedFile.SaveAs(filePath);

                    Teaching teaching = new Teaching();
                    teaching.Guid = guid;
                    teaching.Username = User.Identity.Name;

                    if (!string.IsNullOrEmpty(rename))
                    {
                        teaching.RealName = rename + Path.GetExtension(selectedFile.FileName);
                    }
                    else
                    {
                        teaching.RealName = selectedFile.FileName;
                    }

                    teaching.DOC = DateTime.Now;
                    db.Teachings.Add(teaching);
                    db.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch { ViewBag.Message = "Upload failed"; return RedirectToAction("Index"); }
        }