// PUT api/Album/5 public IHttpActionResult PuttblAlbum(int id, tblAlbum tblalbum) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tblalbum.Albm_id) { return(BadRequest()); } db.Entry(tblalbum).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tblAlbumExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
// GET: /Store/Browse public ActionResult Details(int albumId, int?imageId = null, int?processedImageId = null, int?conditionId = null, int?featureId = null) { string message = HttpUtility.HtmlEncode("Store.Browse, Album = " + albumId); tblAlbum selectedAlbum = null; tblImage selectedMasterImage = null; tblProcessedImage selectedProcessedImage = null; selectedAlbum = imageDB.tblAlbums.SingleOrDefault(a => a.ALB_IDPkey == albumId); var query = imageDB.tblImages.Where(i => i.ALB_IDFkey == albumId); List <tblImage> images = query.ToList(); if (imageId != null) { selectedMasterImage = images.SingleOrDefault(i => i.IMG_IDPkey == imageId); } else { selectedMasterImage = images.FirstOrDefault(); } int selectedIndex = images.IndexOf(selectedMasterImage); int nextIndex = images.Count() - 1; int previousIndex = 0; if (images.Count() - 1 > selectedIndex) { nextIndex = selectedIndex + 1; } if (selectedIndex - 1 >= 0) { previousIndex = selectedIndex - 1; } if (processedImageId != null) { selectedProcessedImage = selectedMasterImage.tblProcessedImages.SingleOrDefault(p => p.PIM_IDPkey == processedImageId.Value); } else { selectedProcessedImage = selectedMasterImage.tblProcessedImages.SingleOrDefault(p => p.tblFilter.FLT_Name == "JPEG"); } var viewModel = new ImageDetailsViewModel { Image = selectedMasterImage, NextImage = images.ElementAt(nextIndex), PreviousImage = images.ElementAt(previousIndex), ProcessedImage = selectedProcessedImage, AvailableConditions = selectedAlbum.tblImages.Select(i => i.tblEnvironmentalCondition).Distinct().ToList(), AvailableFeatures = selectedAlbum.tblImages.Select(i => i.tblFeature).Distinct().ToList() }; return(this.View(viewModel)); }
public IHttpActionResult GettblAlbum(int id) { tblAlbum tblalbum = db.tblAlbums.Find(id); if (tblalbum == null) { return(NotFound()); } return(Ok(tblalbum)); }
public IHttpActionResult PosttblAlbum(tblAlbum tblalbum) { ModelState.Remove("Albm_id"); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.tblAlbums.Add(tblalbum); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = tblalbum.Albm_id }, tblalbum)); }
public IHttpActionResult DeletetblAlbum(int id) { tblAlbum tblalbum = db.tblAlbums.Find(id); if (tblalbum == null) { return(NotFound()); } db.tblAlbums.Remove(tblalbum); db.SaveChanges(); return(Ok(tblalbum)); }
public string AddImage(string ddlAlbums, string ddlConditions, string ddlFeatures) { var image = new tblImage(); try { var dbCtx = new CUATRGEntities4(); tblAlbum album = dbCtx.tblAlbums.FirstOrDefault(a => a.ALB_Name == ddlAlbums); if (album == null) { album = dbCtx.tblAlbums.Create(); album.ALB_Name = ddlAlbums; album.ALB_Description = ddlAlbums; } tblEnvironmentalCondition condition = dbCtx.tblEnvironmentalConditions.FirstOrDefault(a => a.ENC_Name == ddlConditions); if (condition == null) { condition = dbCtx.tblEnvironmentalConditions.Create(); condition.ENC_Name = ddlConditions; condition.ENC_Description = ddlConditions; } tblFeature feature = dbCtx.tblFeatures.FirstOrDefault(a => a.FTR_Name == ddlFeatures); if (feature == null) { feature = dbCtx.tblFeatures.Create(); feature.FTR_Name = ddlFeatures; } image.tblAlbum = album; image.tblEnvironmentalCondition = condition; image.tblFeature = feature; log.Info("Saving files started"); var files = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files : null; log.InfoFormat("Files {0} , Album {1}, Condition {2}, Feature {3} ", string.Join(",", files.AllKeys), ddlAlbums, ddlConditions, ddlFeatures); if (files != null) { foreach (var file in files.AllKeys) { var path = string.Format("~/Images/Albums/{0}", ddlAlbums); var relativePath = string.Format("Images/Albums/{0}", ddlAlbums); var fileName = files[file].FileName; if (fileName.Contains("Image") || fileName.Contains("IMG")) { image.IMG_Name = fileName; image.IMG_Path = relativePath; } else if (fileName.Contains("Sensor")) { image.IMG_SensorDataPath = relativePath; } else if (fileName.Contains("Meta")) { image.IMG_MetaDataPath = relativePath; } if (ImageHelper.IsExists(image)) { throw new InvalidOperationException("Image Exists"); } var mappedPath = System.Web.Hosting.HostingEnvironment.MapPath(path); var filePath = Path.Combine(mappedPath, Path.GetFileName(fileName)); if (!Directory.Exists(mappedPath)) { log.Info("Creating directory"); Directory.CreateDirectory(mappedPath); } string user = System.Security.Principal.WindowsIdentity.GetCurrent().User.Value; var uploadedFile = files[file]; uploadedFile.SaveAs(filePath); } } log.Info("Saving files completed"); log.Info("Retriving Exif data started"); ImageHelper.ExtractMetaData(image); log.Info("Saving db data started"); //Add newStudent entity into DbEntityEntry and mark EntityState to Added dbCtx.Entry(image).State = EntityState.Added; // call SaveChanges method to save new Student into database dbCtx.SaveChanges(); log.Info("Saving db data completed"); return("OK"); } catch (DbEntityValidationException ex) { var valErrors = ex.EntityValidationErrors.SelectMany(e => e.ValidationErrors); var error = string.Join(",", valErrors.Select(e => e.ErrorMessage)); log.Error(string.Format("Error uploading image {0} - {1}", image.IMG_Name, error), ex); return("ERROR:" + ex.Message.ToString()); } catch (Exception ex) { log.Error(string.Format("Error saving image {0}", image.IMG_Name), ex); return(ex.ToString()); } }
public ActionResult AddImage(string name, string ddlAlbums, string ddlConditions, string ddlFeatures, HttpPostedFileBase masterimage, HttpPostedFileBase sensordata) { var image = new tblImage(); try { int albumId = -1; if (!int.TryParse(ddlAlbums, out albumId)) { throw new InvalidDataException("Error in album id"); } int conditionid = -1; if (!int.TryParse(ddlConditions, out conditionid)) { throw new InvalidDataException("Error in condition id"); } int filterId = -1; if (!int.TryParse(ddlFeatures, out filterId)) { throw new InvalidDataException("Error in filter id"); } //set image data image.IMG_Name = name; var dbCtx = new CUATRGEntities4(); tblAlbum album = dbCtx.tblAlbums.FirstOrDefault(a => a.ALB_IDPkey == albumId); tblEnvironmentalCondition condition = dbCtx.tblEnvironmentalConditions.FirstOrDefault(a => a.ENC_IDPkey == conditionid); tblFeature feature = dbCtx.tblFeatures.FirstOrDefault(a => a.FTR_IDPkey == filterId); image.tblAlbum = album; image.tblEnvironmentalCondition = condition; image.tblFeature = feature; image.IMG_Path = string.Format("Images/Albums/{0}", album.ALB_Name); image.IMG_SensorDataPath = string.Format("Images/Albums/{0}", album.ALB_Name); string[] imagaeData = masterimage.FileName.Split('\\'); image.IMG_Name = imagaeData[imagaeData.Length - 1]; if (ImageHelper.IsExists(image)) { throw new InvalidOperationException("Image Exists"); } log.Info("Saving files started"); FileHelper.SaveFile(image, masterimage, image.IMG_Name); FileHelper.SaveFile(image, sensordata, image.IMG_Name.Replace("IMG", "SensorData").Replace("jpg", "csv")); log.Info("Saving files completed"); log.Info("Retriving Exif data started"); ImageHelper.ExtractMetaData(image); log.Info("Saving db data started"); //Add newStudent entity into DbEntityEntry and mark EntityState to Added dbCtx.Entry(image).State = EntityState.Added; // call SaveChanges method to save new Student into database dbCtx.SaveChanges(); log.Info("Saving db data completed"); log.Info("View generation completed"); ViewBag.Message = "Successfully uploaded"; } catch (Exception ex) { log.Error(string.Format("Error uploading image {0}", image.IMG_Name)); ViewBag.Message = "ERROR:" + ex.Message.ToString(); } var viewModel = new AddImageViewModel() { Albums = imageDB.tblAlbums.ToList(), Conditions = imageDB.tblEnvironmentalConditions.ToList(), Features = imageDB.tblFeatures.ToList() }; return(View(viewModel)); }