public Guid Add(ImageCreateVM image) { var currentImage = new Image() { Data = image.Data, MimeType = image.MimeType, }; return(_images.Add(currentImage)); }
public ActionResult ImageAdd(ImageCreateVM model) { var path = ""; var user = User as MPrincipal; var login = user.UserDetails.Login; ViewBag.UserName = user.UserDetails.Login; ViewBag.UserRole = 4; if (model.File != null) { if (model.File.ContentLength > 0) { if (Path.GetExtension(model.File.FileName).ToLower() == ".jpg" || Path.GetExtension(model.File.FileName).ToLower() == ".png" || Path.GetExtension(model.File.FileName).ToLower() == ".gif" || Path.GetExtension(model.File.FileName).ToLower() == ".jpeg") { path = Path.Combine(Server.MapPath(@"\AppImages"), login.ToString() + "_" + model.File.FileName); //path = @"D:\EkipaApp\Ekipa\Ekipa\AppImages\" + login.ToString() + "_" + model.File.FileName; model.File.SaveAs(path); ViewBag.UploadSuccess = true; using (ApplicationDbContext db = new ApplicationDbContext()) { var company = db.Companies.SingleOrDefault(x => x.Login == login); var image = new Image() { CompanyId = company.Id, Description = model.Description, Link = @"~/AppImages/" + login.ToString() + "_" + model.File.FileName, IsDelete = false, MainPicture = false }; db.Images.Add(image); db.SaveChanges(); } } } } return(RedirectToAction("CompanyImagesList")); }