public ActionResult Edit(int? id) { var user = DisplayCurUser(); if (!user.HasAccess(AdGroup.VendorStateEditor)) return new HttpStatusCodeResult(403); if (id.HasValue) { var vnd = new VendorState(id.Value); return View(vnd); } else { return View("New"); } }
public ActionResult Edit(VendorState vnd) { /*var user = DisplayCurUser(); if (!user.UserCanEdit()) return RedirectToAction("AccessDenied", "Error");*/ //Save employee try { ResponseMessage responseMessage; bool complete = SaveVendorState(vnd, out responseMessage); if (!complete) throw new Exception(responseMessage.ErrorMessage); return RedirectToAction("Index", "VendorState"); } catch (Exception ex) { TempData["ServerError"] = ex.Message; return View("Edit", vnd); } }
private void FillSelf(VendorState vnd) { Id = vnd.Id; StateName = vnd.StateName; VendorId = vnd.VendorId; VendorName = vnd.VendorName; StateDescription = vnd.StateDescription; Picture = vnd.Picture; EndDate = vnd.EndDate; UnitOrganizationId = vnd.UnitOrganizationId; LanguageId = vnd.LanguageId; }
public ActionResult GetImage(int id) { var vnd = new VendorState(id); byte[] imageData = vnd.Picture; if (imageData != null) return File(imageData, "image/jpeg"); else return null;// Might need to adjust the content type based on your actual image type }
public bool SaveVendorState(VendorState vnd, out ResponseMessage responseMessage) { if (Request.Files.Count > 0 && Request.Files[0] != null && Request.Files[0].ContentLength > 0) { var file = Request.Files[0]; if (file.ContentLength > 5242880) { responseMessage = new ResponseMessage(); responseMessage.ErrorMessage = "Нельзя загрузить файл размером более 5 мегабайт. Файл не был загружен."; return false; } string ext = Path.GetExtension(file.FileName).ToLower(); if (ext != ".jpeg" && ext != ".jpg") throw new Exception("Формат фотографии должен быть jpeg"); byte[] picture = null; using (var br = new BinaryReader(file.InputStream)) { picture = br.ReadBytes(file.ContentLength); } vnd.Picture = picture; } //var chkCreateAdUser = Request.Form["chkCreateAdUser"]; //bool createAdUser = chkCreateAdUser != "false";. if (vnd.EndDate.Equals(new DateTime())) vnd.EndDate=new DateTime(3333,3,3); bool complete = vnd.Save(out responseMessage); return complete; }
public ActionResult Image(int? id) { var user = DisplayCurUser(); /* if (!user.UserCanEdit()) return RedirectToAction("AccessDenied", "Error");*/ if (id.HasValue) { var vnd = new VendorState(id.Value); return View(vnd); } else { return RedirectToAction("Index", "VendorState"); } }