public ActionResult DeleteConfirmed(int id) { Models.Photo photo = context.FindPhotoById(id); context.Delete <Photo>(photo); context.SaveChanges(); return(RedirectToAction("Index")); }
public HttpResponseMessage Put(int id, [FromBody] Models.Photo updatedPhoto) { updatedPhoto.Id = id; ServiceData.Models.Photo found = _photoRepository.GetById(id); if (found == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } if (!IsSameUser(found)) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } ServiceData.Models.Photo final = _photoRepository.Update(Models.Photo.ToServiceModel(updatedPhoto, true)); if (final == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } UpdateShares(final); ServerUtils.LogTelemetryEvent(User.Identity.Name, "UpdatePhoto"); PostLog("Photos_Update"); return(Request.CreateResponse(HttpStatusCode.OK, Models.Photo.ToAppModel(final, true))); }
private void GoToCommand1(string token, int type, string method, string idTaskNo) { if (method == "SavePhoto") { string obj = CrossSettings.Current.GetValueOrDefault(idTaskNo, ""); string vehiclwInformationId = CrossSettings.Current.GetValueOrDefault(idTaskNo + "Param", ""); byte[] photoInspectionArray = Convert.FromBase64String(obj); string photoInspectionjson = Encoding.Default.GetString(photoInspectionArray); Models.PhotoInspection photoInspection = JsonConvert.DeserializeObject <Models.PhotoInspection>(photoInspectionjson); TaskManager.CommandToDo("SavePhoto", type, token, vehiclwInformationId, photoInspection); } else if (method == "SaveInspactionDriver") { string obj = CrossSettings.Current.GetValueOrDefault(idTaskNo, ""); string[] paramss = CrossSettings.Current.GetValueOrDefault(idTaskNo + "Param", "").Split(','); string IdDriver = paramss[0]; string IndexCurent = paramss[1]; byte[] photoArray = Convert.FromBase64String(obj); string photojson = Encoding.Default.GetString(photoArray); Models.Photo photo = JsonConvert.DeserializeObject <Models.Photo>(photojson); TaskManager.CommandToDo("SaveInspactionDriver", type, token, IdDriver, photo, IndexCurent); } else if (method == "SaveRecount") { string obj = CrossSettings.Current.GetValueOrDefault(idTaskNo, ""); string[] paramss = CrossSettings.Current.GetValueOrDefault(idTaskNo + "Param", "").Split(','); string idShip = paramss[0]; string typeVideo = paramss[1]; byte[] videoArray = Convert.FromBase64String(obj); string videojson = Encoding.Default.GetString(videoArray); Video video = JsonConvert.DeserializeObject <Video>(videojson); TaskManager.CommandToDo("SaveRecount", type, token, idShip, 1, video); } }
public ActionResult Delete(int id) { Models.Photo photo = context.FindPhotoById(id); if (photo == null) { return(HttpNotFound()); } return(View("Delete", photo)); }
public async Task <ImageSource> Resolve( Unsplasharp.Models.Photo source, Models.Photo destination, Task <ImageSource> destMember, ResolutionContext context) { var bitmapSource = await GenerateBlurHash(source.BlurHash ?? "LEHV6nWB2yk8pyo0adR*.7kCMdnj", source.Width, source.Height); return(bitmapSource); }
public FileContentResult GetImage(int id) { Models.Photo photo = context.FindPhotoById(id); if (photo != null && photo.PhotoFile != null) { return(File(photo.PhotoFile, photo.ImageMimeType)); } else { return(null); } }
public Photos MapToDbPhoto(Models.Photo clientPhoto, int orderId) { if (clientPhoto == null) { return(null); } return(new Photos { orderId = orderId, photoUrl = clientPhoto.photoUrl, selected = clientPhoto.selected }); }
public ActionResult Creer(FormCollection dictio) { if (dictio["Titre"] != null) { using (Models.KartinaDotNetFrameworkEntities1 context = new Models.KartinaDotNetFrameworkEntities1()) { Models.Photo photo = new Models.Photo(); photo.Title = dictio["Titre"]; photo.IdVendeur = 5; context.Photo.Add(photo); context.SaveChanges(); } } return(this.View()); }
public async Task <HttpResponseMessage> Post([FromBody] Models.Photo newPhoto) { try { ServiceData.Models.Photo returned = _photoRepository.Insert(Models.Photo.ToServiceModel(newPhoto, true)); UpdateShares(returned); ServerUtils.LogTelemetryEvent(User.Identity.Name, "AddPhoto"); PostLog("Photos_Create"); return(Request.CreateResponse(HttpStatusCode.OK, Models.Photo.ToAppModel(returned, false))); } catch (Exception e) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, e)); } }
public static Photo AsStore(this Models.Photo source) => new Photo { Id = source.PhotoId, Type = source.Type.ToString(), TypeId = source.TypeId, Filename = source.Filename, BlobPath = source.BlobPath, ExternalUrl = source.ExternalUrl, LocationId = source.Location?.LocationId, ContentType = source.ContentType, Height = source.Height, Width = source.Width, DateTaken = source.DateTaken, CreatedBy = source.CreatedBy, ModifiedBy = source.ModifiedBy, DateCreated = source.DateCreated ?? DateTime.UtcNow, DateModified = source.DateModified };
public HttpResponseMessage Get(int id) { ServiceData.Models.Photo found = _photoRepository.GetById(id); if (found == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } if (!IsSameUser(found)) { return(Request.CreateResponse(HttpStatusCode.Forbidden)); } Models.Photo toRet = Models.Photo.ToAppModel(found, false); ServerUtils.LogTelemetryEvent(User.Identity.Name, "GetPhoto"); PostLog("Photos_GetSingle"); return(Request.CreateResponse(HttpStatusCode.OK, toRet)); }
public ActionResult Add(Models.Photo imageModel) { string fileName = Path.GetFileNameWithoutExtension(imageModel.ImageFile.FileName); string extension = Path.GetExtension(imageModel.ImageFile.FileName); fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; imageModel.Image = "~/Images/" + fileName; fileName = Path.Combine(Server.MapPath("~/Images/"), fileName); imageModel.ImageFile.SaveAs(fileName); using (Models.ParkSomewhereAppEntities db = new Models.ParkSomewhereAppEntities()) { imageModel.UserID = User.Identity.GetUserId(); db.Photos.Add(imageModel); db.SaveChanges(); } ModelState.Clear(); ViewBag.ParkID = new SelectList(db.Parks, "ParkID", "ParkName", imageModel.ParkID); ViewBag.UserID = new SelectList(db.AspNetUsers, "Id", "Email", imageModel.UserID); return(RedirectToAction("Index", "Photos")); }
internal void AddPhotoDocumments(byte[] result) { isAsk2 = true; if (ask2PageMW.Ask2.Any_additional_documentation_been_given_after_loading == null) { ask2PageMW.Ask2.Any_additional_documentation_been_given_after_loading = new List <Models.Photo>(); } Models.Photo photo = new Models.Photo(); photo.Base64 = Convert.ToBase64String(result); photo.path = $"../Photo/{ask2PageMW.IdVech}/PikedUp/Documment/{ask2PageMW.Ask2.Any_additional_documentation_been_given_after_loading.Count + 1}.jpg"; ask2PageMW.Ask2.Any_additional_documentation_been_given_after_loading.Add(photo); Image image = new Image() { Source = ImageSource.FromStream(() => new MemoryStream(result)), HeightRequest = 50, WidthRequest = 50, }; //image.GestureRecognizers.Add(new TapGestureRecognizer(ViewPhotoForRetacke1)); blockAskPhotoDocumments.Children.Add(image); }
public void AddPhotoItems(byte[] photob) { if (askPageMV.Ask.Any_personal_or_additional_items_with_or_in_vehicle == null) { askPageMV.Ask.Any_personal_or_additional_items_with_or_in_vehicle = new List <Models.Photo>(); } Models.Photo photo = new Models.Photo(); photo.Base64 = Convert.ToBase64String(photob); photo.path = $"../Photo/{askPageMV.VehiclwInformation.Id}/PikedUp/Items/{askPageMV.Ask.Any_personal_or_additional_items_with_or_in_vehicle.Count + 1}.jpg"; askPageMV.Ask.Any_personal_or_additional_items_with_or_in_vehicle.Add(photo); Image image = new Image() { Source = ImageSource.FromStream(() => new MemoryStream(photob)), HeightRequest = 50, WidthRequest = 50, }; image.GestureRecognizers.Add(new TapGestureRecognizer(ViewPhotoForRetacke1)); blockAskPhotoItem.Children.Add(image); GC.Collect(); GC.WaitForPendingFinalizers(); }
public async Task<IEnumerable<PhotoDto>> Upload(HttpRequestMessage request) { int galleryId = int.Parse(request.Headers.GetValues("x-galleryId").Single()); var gallery = uow.Galleries.GetAll() .Include(x=>x.GalleryPhotos) .Include("GalleryPhotos.Photo") .Where(x=> x.Id == galleryId).Single(); string workingFolder = System.Web.HttpContext.Current.Server.MapPath("~/Uploads"); var provider = new PhotoMultipartFormDataStreamProvider(workingFolder); await request.Content.ReadAsMultipartAsync(provider); var photos = new List<PhotoDto>(); foreach (var file in provider.FileData) { var fileInfo = new FileInfo(file.LocalFileName); var photo = new Models.Photo(); if (uow.Photos.GetAll().Where(x => x.Name == fileInfo.Name).FirstOrDefault() != null) { photo = uow.Photos.GetAll().Where(x => x.Name == fileInfo.Name).Single(); } else { uow.Photos.Add(photo); } photo.Name = fileInfo.Name; photo.Created = fileInfo.CreationTime; photo.Modified = fileInfo.LastWriteTime; photo.Size = fileInfo.Length / 1024; if(gallery.GalleryPhotos.Where(x=>x.Photo.Name == photo.Name).FirstOrDefault() == null) { var galleryPhoto = new GalleryPhoto(); galleryPhoto.Photo = photo; gallery.GalleryPhotos.Add(galleryPhoto); } uow.SaveChanges(); } return photos; }
public ActionResult Create(Models.Photo photo, HttpPostedFileBase image) { photo.CreatedDate = DateTime.Today; if (!ModelState.IsValid) { return(View("Create", photo)); } else { if (image != null) { photo.ImageMimeType = image.ContentType; photo.PhotoFile = new byte[image.ContentLength]; image.InputStream.Read(photo.PhotoFile, 0, image.ContentLength); } context.Add <Photo>(photo); context.SaveChanges(); return(RedirectToAction("Index")); } }
public void AddPhoto(byte[] result) { if (askDelyveryMV.AskDelyvery.Please_take_a_picture_Id_of_the_person_taking_the_delivery == null) { askDelyveryMV.AskDelyvery.Please_take_a_picture_Id_of_the_person_taking_the_delivery = new List <Models.Photo>(); } Models.Photo photo = new Models.Photo(); photo.Base64 = Convert.ToBase64String(result); photo.path = $"../Photo/{askDelyveryMV.VehiclwInformation.Id}/PikedUp/Items/{askDelyveryMV.AskDelyvery.Please_take_a_picture_Id_of_the_person_taking_the_delivery.Count + 1}.jpg"; askDelyveryMV.AskDelyvery.Please_take_a_picture_Id_of_the_person_taking_the_delivery.Add(photo); Image image = new Image() { Source = ImageSource.FromStream(() => new MemoryStream(result)), HeightRequest = 50, WidthRequest = 50, }; //image.GestureRecognizers.Add(new TapGestureRecognizer(ViewPhotoForRetacke1)); blockPhoto.Children.Add(image); isAsk7 = true; GC.Collect(); GC.WaitForPendingFinalizers(); }
public async Task<IActionResult> Upload(IList<IFormFile> files, int? id, Int16? kind, int? kindId) { foreach (var file in files) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"').ToLower();// FileName returns "fileName.ext"(with double quotes) in beta 3 if (fileName.EndsWith(".jpg") || fileName.EndsWith(".png") || fileName.EndsWith(".gif") || fileName.EndsWith(".bmp") || fileName.EndsWith(".tif") || fileName.EndsWith(".tiff") || fileName.EndsWith(".ico") || fileName.EndsWith(".pdf") )// Important for security if saving in webroot { Photo photo = null; if (id.HasValue) { photo = await FindPhotoAsync(id.Value); } else { photo = new Models.Photo(); photo.Kind = kind.Value; photo.KindId = kindId.Value; } photo.Name = Path.GetFileName(fileName); var filePath = Path.Combine(_environment.WebRootPath, "uploads", photo.Name) ; using (Stream str = file.OpenReadStream()) { //byte[] buf = new byte[file.Length]; //str.Read(buf, 0, buf.Length); //photo.Content = buf; using (MemoryStream data = new MemoryStream()) { str.CopyTo(data); data.Seek(0, SeekOrigin.Begin); // <-- missing line byte[] buf = new byte[data.Length]; data.Read(buf, 0, buf.Length); photo.Content = buf; } } //await file.SaveAsAsync(filePath); //photo.Content = System.IO.File.ReadAllBytes(filePath); db.Photos.Add(photo); await db.SaveChangesAsync(); // save the image path path to the database or you can send image // directly to database // in-case if you want to store byte[] ie. for DB //using (MemoryStream ms = new MemoryStream()) //{ // file2.InputStream.CopyTo(ms); // byte[] array = ms.GetBuffer(); //} } } return RedirectToAction("Index", new { kind = kind, kindId = kindId });// PRG //return View(); }
public PhotoModule(IDBFactory dbFactory) : base(dbFactory, "/photo") { Get["/{slug}"] = parameters => { string slug = (string)parameters.slug; Models.Photo photo = DB.Photos.FindBySlug(slug); if (photo == null) { // No photo found with this slug, we'll just redirect to the homepage return(Response.AsRedirect("/")); } else { var model = new Models.PhotoDetail(); model.Photo = photo; model.PreviousSlug = DB.Photos.Query().Select(DB.Photos.Slug).Where(DB.Photos.Published == true && DB.Photos.DatePublished < photo.DatePublished.Value).OrderByDatePublishedDescending().Take(1).ToScalarOrDefault <string>(); model.NextSlug = DB.Photos.Query().Select(DB.Photos.Slug).Where(DB.Photos.Published == true && DB.Photos.DatePublished > photo.DatePublished.Value).OrderByDatePublished().Take(1).ToScalarOrDefault <string>(); IEnumerable <Models.Comment> comments = DB.Comments.FindAll(DB.Comments.PhotoId == model.Photo.Id && DB.Comments.Approved == true).Cast <Models.Comment>(); if (comments != null) { model.Comments = comments.ToList(); } bool commenterror = false; if (Boolean.TryParse(Convert.ToString(Session["commenterror"]), out commenterror)) { model.ErrorMessage = "Please fill out all required fields and make sure the email address you enter is valid."; Session.Delete("commenterror"); } return(View["photodetail", model]); } }; Post["/{slug}/addcomment"] = parameters => { string photoSlug = (string)parameters.slug; int?photoId = DB.Photos.Query().Select(DB.Photos.Id).Where(DB.Photos.Slug == photoSlug).ToScalarOrDefault <int?>(); if (photoId.HasValue) { Models.Comment comment = this.Bind <Models.Comment>("Id", "PhotoId", "Approved"); comment.PhotoId = photoId.Value; comment.Approved = true; if (comment.IsValid()) { DB.Comments.Insert(comment); } else { Session["commenterror"] = true; } return(Response.AsRedirect(String.Format("/photo/{0}#comments", photoSlug))); } else { // No photo found with this slug, we'll just redirect to the homepage return(Response.AsRedirect("/")); } }; }
public ActionResult Create() { Models.Photo newPhoto = new Models.Photo(); newPhoto.CreatedDate = DateTime.Today; return(View("Create", newPhoto)); }
public IActionResult OnGet(int selectedPhotoAlbumId, int selectedPhotoCategoryId, int photoId, bool myAlbums = false) { //Used to pass selected categroy into page for button links to preserve selection SelectedPhotoCategoryId = selectedPhotoCategoryId; //Used to pass myAlbums into page for button links to preserve selection MyAlbums = myAlbums; //Get Id of current user. OwnerId = _userManager.GetUserId(User); PhotoObj = new Models.Photo(); //Existing Photo (edit) //Ignores selectedPhotoAlbumId, uses existing database entry. if (photoId != 0) { PhotoObj = _unitOfWork.Photo.GetFirstOrDefault(p => p.Id == photoId); if (PhotoObj == null) { return(RedirectToPage("/Home/Photos/Index", new { selectedPhotoCategoryId = selectedPhotoCategoryId, myAlbums = myAlbums })); } SelectedPhotoAlbum = _unitOfWork.PhotoAlbum.GetFirstOrDefault(a => a.Id == PhotoObj.PhotoAlbumId); } //New photo, add it to the selected album if (photoId == 0) { //No selectedPhotoAlbumId entered: invalid if (selectedPhotoAlbumId == 0) { return(RedirectToPage("/Home/Photos/Index", new { selectedPhotoCategoryId = selectedPhotoCategoryId, myAlbums = myAlbums })); } SelectedPhotoAlbum = _unitOfWork.PhotoAlbum.GetFirstOrDefault(a => a.Id == selectedPhotoAlbumId); //Ensure selectedPhotoAlbumId is an existing album if (SelectedPhotoAlbum != null) { //Pass the album in PhotoObj.PhotoAlbumId = selectedPhotoAlbumId; } else { return(RedirectToPage("/Home/Photos/Index", new { selectedPhotoCategoryId = selectedPhotoCategoryId, myAlbums = myAlbums })); } } //Only allow admins and creator to access if (User.IsInRole(SD.AdministratorRole) || SelectedPhotoAlbum.OwnerId == OwnerId) { return(Page()); } else { return(RedirectToPage("/Home/Photos/Index", new { selectedPhotoCategoryId = selectedPhotoCategoryId, myAlbums = myAlbums })); } }
public IActionResult CreatePhotosAlbum(ICollection <Microsoft.AspNet.Http.IFormFile> Productphoto_file, Photo model, int?id) { try { if (ModelState.IsValid) { if (Productphoto_file.Count > 0) { foreach (var file in Productphoto_file) { if (file.Length > 1024 * 1024) { TempData["ErrorMessage"] = "حجم فایل انتخاب شده بیش از یک مگابایت است. لطفا فایل دیگری انتخاب نمایید"; break; } else if (file.Length == 0) { TempData["ErrorMessage"] = "حجم فایل انتخاب شده صفر بایت است. لطفا فایل دیگری انتخاب نمایید"; break; } else { var fileName = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); // file.SaveAsAsync(Path.Combine(uploads, fileName)); // read content instead using (Stream sr = file.OpenReadStream()) { byte[] fileData = null; using (MemoryStream msOrig = Utils.LoadToMemoryStream(sr)) { // resize it // todo: we always resize profile image to 140x140 Image img = Bitmap.FromStream(msOrig); Bitmap bmp = new Bitmap(img, new Size(340, 340)); MemoryStream ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); // read content instead fileData = Utils.ConvertMemoryStreamToBytes(ms); ms.Dispose(); bmp.Dispose(); img.Dispose(); } //_db = new DALContext(); Models.Photo Photo = new Models.Photo(); var SerchAlbumId = _db.Albums.FirstOrDefault(x => x.Id == id); if (SerchAlbumId != null) { Photo.ImgData = new Byte[fileData.Length]; Photo.ImgType = "jpg"; Buffer.BlockCopy(fileData, 0, Photo.ImgData, 0, fileData.Length); Photo.Album = SerchAlbumId; //ViewBag.AlbumTitell = SerchAlbumId.Titel; Photo.Titel = model.Titel; _db.Photoes.Add(Photo); _db.SaveChanges(); TempData["ErrorMessage"] = "درج با موفقیت انجام شد"; } } } } } else { TempData["ErrorMessage"] = "لطفا یک عکس انتخاب نمایید "; } } else { TempData["ErrorMessage"] = "لطفا یک عکس انتخاب کنید و عنوان را وارد نمایید "; } ViewBag.id = id; return(View()); } catch (Exception ex) { return(RedirectToAction(nameof(HomeController.Error), "Home")); } }
public async Task <IActionResult> Upload(IList <IFormFile> files, int?id, Int16?kind, int?kindId) { foreach (var file in files) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"').ToLower();// FileName returns "fileName.ext"(with double quotes) in beta 3 if (fileName.EndsWith(".jpg") || fileName.EndsWith(".png") || fileName.EndsWith(".gif") || fileName.EndsWith(".bmp") || fileName.EndsWith(".tif") || fileName.EndsWith(".tiff") || fileName.EndsWith(".ico") || fileName.EndsWith(".pdf") )// Important for security if saving in webroot { Photo photo = null; if (id.HasValue) { photo = await FindPhotoAsync(id.Value); } else { photo = new Models.Photo(); photo.Kind = kind.Value; photo.KindId = kindId.Value; } photo.Name = Path.GetFileName(fileName); var filePath = Path.Combine(_environment.WebRootPath, "uploads", photo.Name); using (Stream str = file.OpenReadStream()) { //byte[] buf = new byte[file.Length]; //str.Read(buf, 0, buf.Length); //photo.Content = buf; using (MemoryStream data = new MemoryStream()) { str.CopyTo(data); data.Seek(0, SeekOrigin.Begin); // <-- missing line byte[] buf = new byte[data.Length]; data.Read(buf, 0, buf.Length); photo.Content = buf; } } //await file.SaveAsAsync(filePath); //photo.Content = System.IO.File.ReadAllBytes(filePath); db.Photos.Add(photo); await db.SaveChangesAsync(); // save the image path path to the database or you can send image // directly to database // in-case if you want to store byte[] ie. for DB //using (MemoryStream ms = new MemoryStream()) //{ // file2.InputStream.CopyTo(ms); // byte[] array = ms.GetBuffer(); //} } } return(RedirectToAction("Index", new { kind = kind, kindId = kindId }));// PRG //return View(); }