public SetPixelColorDialog(ImageCategory cat, int bpp) { InitializeComponent(); _imgCat = cat; _maxValue = (int)Math.Pow(2, bpp) - 1; _minValue = 0; }
//TODO:Build the common code for Folder creation(Inprogress).Need to remove unnecessary above lines in above code private string CreateFolder(ImageCategory ImageCategory) { var imagePhysicalPath = ConfigurationManager.AppSettings["IMAGE_PHYSICAL_PATH"].ToString(); imagePhysicalPath = Path.Combine(imagePhysicalPath, accountId); if (!System.IO.Directory.Exists(imagePhysicalPath)) { System.IO.Directory.CreateDirectory(imagePhysicalPath); } switch (ImageCategory) { case ImageCategory.ContactProfile: imagePhysicalPath = Path.Combine(imagePhysicalPath, "pi"); break; case ImageCategory.Campaigns: imagePhysicalPath = Path.Combine(imagePhysicalPath, "ci"); break; case ImageCategory.AccountLogo: imagePhysicalPath = Path.Combine(imagePhysicalPath, "ai"); break; default: imagePhysicalPath = string.Empty; break; } if (!System.IO.Directory.Exists(imagePhysicalPath)) { System.IO.Directory.CreateDirectory(imagePhysicalPath); } return(imagePhysicalPath); }
/// <summary> /// Geting Image Physical Path /// </summary> /// <param name="Account">Account Name</param> /// <param name="ImageCategory"> Image Category</param> /// <returns>Image Pysical Path </returns> private string CreateFolder(string Account, ImageCategory ImageCategory) { var imagePhysicalPath = ConfigurationManager.AppSettings["IMAGE_PHYSICAL_PATH"].ToString(); imagePhysicalPath = Path.Combine(imagePhysicalPath, Account); //Account Folder if (!System.IO.Directory.Exists(imagePhysicalPath)) { System.IO.Directory.CreateDirectory(imagePhysicalPath); } switch (ImageCategory) { case ImageCategory.ContactProfile: imagePhysicalPath = Path.Combine(imagePhysicalPath, "pi"); break; case ImageCategory.Campaigns: imagePhysicalPath = Path.Combine(imagePhysicalPath, "ci"); break; default: throw new NotImplementedException(); } //ImageCategory Folder if (!System.IO.Directory.Exists(imagePhysicalPath)) { System.IO.Directory.CreateDirectory(imagePhysicalPath); } return(imagePhysicalPath); }
//TODO:Once we will get the accountname from identity then public ImageViewModel SaveImages(ImageViewModel viewModel, ImageCategory ImageCategory) { if (viewModel.ImageContent != null) { if (!string.IsNullOrEmpty(viewModel.StorageName) && viewModel.ImageContent.Contains(viewModel.StorageName)) { return(null); } System.Drawing.Image Image; string storageName = string.Empty; if (viewModel.ImageID != 0) { storageName = viewModel.StorageName; } else { storageName = Guid.NewGuid().ToString() + viewModel.ImageType; } try { string imagePath = CreateFolder(ImageCategory); imagePath = Path.Combine(imagePath, storageName); if (System.IO.File.Exists(imagePath)) { System.IO.File.Delete(imagePath); } if (!System.IO.File.Exists(imagePath)) { if (viewModel.ImageContent.Split(',').Length == 2) { string imageContent = viewModel.ImageContent.Split(',')[1]; byte[] imageData = Convert.FromBase64String(imageContent); using (MemoryStream ms = new MemoryStream(imageData)) { Image = System.Drawing.Image.FromStream(ms); Image.Save(imagePath); } viewModel.ImageContent = null; viewModel.StorageName = storageName; viewModel.FriendlyName = viewModel.OriginalName; viewModel.ImageCategoryID = ImageCategory; viewModel.AccountID = Convert.ToInt16(accountId); } else { viewModel = null; } } } catch (Exception) { throw; } } else { viewModel = null; } return(viewModel); }
public ActionResult Create(HttpPostedFileBase file, ImageCategory category) { Image image = new Image(); try { if (file == null || file.ContentLength <= 0) { throw new Exception("Plik pusty"); } if (file.ContentLength > 204800) { throw new Exception("Uwaga wielkość pliku przekracza 200kb."); } // Get file info var fileName = Path.GetFileName(file.FileName); //nazwa pliku var imageName = Path.GetFileNameWithoutExtension(fileName); var imageExtension = ""; var contentLength = file.ContentLength; //wielkosc pliku var contentType = file.ContentType; //typ pliku if (contentType == "image/jpeg") { imageExtension = "jpg"; } else if (contentType == "image/png") { imageExtension = "png"; } if (imageExtension == "") { throw new Exception("Uwaga niewłaściwy format zdjęcia. Akceptowane formaty: jpg, png."); } byte[] imageBytes = new byte[contentLength - 1]; using (var binaryReader = new BinaryReader(file.InputStream)) { imageBytes = binaryReader.ReadBytes(file.ContentLength); } image.FileName = String.Format("{0:yyyyMMddHHmmss}.{1}", DateTime.Now, imageExtension); image.Data = imageBytes; image.Type = contentType; image.Category = category; db.Images.Add(image); db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Dodanie zdjęcia przebiegło pomyślnie."); return(RedirectToAction("Index")); } catch (Exception e) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem danych. " + e.Message); } return(View(image)); }
public ImageCategory SaveCategory(ImageCategory category) { if (category.Id > 0) { var dbcategory = _unitOfWork.ImageCategoryRepository.GetByID(category.Id); if (dbcategory != null) { dbcategory.Description = category.Description; dbcategory.IsDeleted = category.IsDeleted; dbcategory.Name = category.Name; dbcategory.IsGallery = category.IsGallery; dbcategory.CategoryUrl = category.CategoryUrl; _unitOfWork.ImageCategoryRepository.Update(dbcategory); } } else { _unitOfWork.ImageCategoryRepository.Insert(category); } _unitOfWork.Save(); return(_unitOfWork.ImageCategoryRepository.GetByID(category.Id)); }
public ActionResult Edit(int?id, HttpPostedFileBase file, ImageCategory category) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var query = from i in db.Images where i.ID == id select i; var image = query.FirstOrDefault(); try { if (!Enum.IsDefined(typeof(ImageCategory), category)) { throw new Exception("Niewłaściwa Katygoria"); } if (file != null) { var fileName = Path.GetFileName(file.FileName); //nazwa pliku var imageName = Path.GetFileNameWithoutExtension(fileName); var imageExtension = ""; var contentLength = file.ContentLength; //wielkosc pliku var contentType = file.ContentType; //typ pliku byte[] imageBytes = new byte[contentLength - 1]; using (var binaryReader = new BinaryReader(file.InputStream)) { imageBytes = binaryReader.ReadBytes(file.ContentLength); } image.FileName = String.Format("{0:yyyyMMddHHmmss}.{1}", DateTime.Now, imageExtension); image.Data = imageBytes; image.Type = contentType; } image.Category = category; db.Entry(image).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Aktualizacja danych przebiegła pomyślnie."); return(RedirectToAction("Index")); } catch (DbUpdateConcurrencyException) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Dane zostały zaktualizowane przez inną osobę. Należy odświeżyć stronę w celu wczytania nowych danych."); } catch (Exception e) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z aktualizowaniem danych. " + e.Message); } return(View(image)); }
/* Server Validations */ private void ImageDBExist(string iName, ImageCategory iCat, int?id = null) { // Unique name and category var dbImage = db.Images.AsNoTracking().FirstOrDefault(i => i.Name == iName && i.Category == iCat); if ((dbImage != null && id == null) || (dbImage != null && dbImage.ID != id)) { ModelState.AddModelError("Name", "An image with that name already exists on this category."); } }
public ImageViewModel DownloadImage(string ImageInputUrl, ImageCategory ImgCategory) { string imageUrl = string.Empty; string storagePath = string.Empty; string storageName = Guid.NewGuid().ToString() + Path.GetExtension(ImageInputUrl); string fileOriginalName = Path.GetFileName(ImageInputUrl); var imagePhysicalPath = ConfigurationManager.AppSettings["IMAGE_PHYSICAL_PATH"].ToString(); ImageViewModel imageViewModel = new ImageViewModel(); if (!System.IO.File.Exists(imagePhysicalPath + "/" + ImageInputUrl)) { WebRequest req = WebRequest.Create(ImageInputUrl); req.Timeout = 10000; WebResponse response = req.GetResponse(); Stream stream = response.GetResponseStream(); System.Drawing.Image Image = System.Drawing.Image.FromStream(stream); if (!System.IO.Directory.Exists(imagePhysicalPath + "/" + accountId)) { Directory.CreateDirectory(imagePhysicalPath + "/" + accountId); } switch (ImgCategory) { case ImageCategory.ContactProfile: storagePath = accountId + "/" + "pi"; imageViewModel.FriendlyName = fileOriginalName; break; case ImageCategory.Campaigns: storagePath = accountId + "/" + "ci"; break; default: storagePath = string.Empty; break; } imagePhysicalPath = imagePhysicalPath + "/" + storagePath; if (!System.IO.Directory.Exists(imagePhysicalPath)) { System.IO.Directory.CreateDirectory(imagePhysicalPath); } imagePhysicalPath = Path.Combine(imagePhysicalPath, storageName); if (!System.IO.File.Exists(imagePhysicalPath)) { Image.Save(imagePhysicalPath); } imageUrl = storageName; imageViewModel.ImageContent = imageUrl; imageViewModel.OriginalName = fileOriginalName; imageViewModel.ImageType = Path.GetExtension(ImageInputUrl); imageViewModel.StorageName = storageName; imageViewModel.ImageCategoryID = ImgCategory; imageViewModel.AccountID = Convert.ToInt16(accountId); } return(imageViewModel); }
public Sprite GetImageByProbability(float range, ImageCategory category) { //Get only one data by PrefabCategory var distinctValues = Images.FindAll(x => x.category == category); range /= distinctValues.Count(); var probs = Images.FindAll(x => x.category == category && x.probability >= range); var rnd = new System.Random(); return(Resources.Load <Sprite>(probs[rnd.Next(0, probs.Count)].name)); }
public ActionResult Create(HttpPostedFileBase file,ImageCategory category) { Image image = new Image(); try { if (file == null || file.ContentLength <= 0) { throw new Exception("Plik pusty"); } if (file.ContentLength > 204800) { throw new Exception("Uwaga wielkość pliku przekracza 200kb."); } // Get file info var fileName = Path.GetFileName(file.FileName); //nazwa pliku var imageName = Path.GetFileNameWithoutExtension(fileName); var imageExtension = ""; var contentLength = file.ContentLength; //wielkosc pliku var contentType = file.ContentType; //typ pliku if (contentType == "image/jpeg") { imageExtension = "jpg";} else if (contentType == "image/png") { imageExtension = "png";} if (imageExtension == "") { throw new Exception("Uwaga niewłaściwy format zdjęcia. Akceptowane formaty: jpg, png."); } byte[] imageBytes = new byte[contentLength - 1]; using (var binaryReader = new BinaryReader(file.InputStream)) { imageBytes = binaryReader.ReadBytes(file.ContentLength); } image.FileName = String.Format("{0:yyyyMMddHHmmss}.{1}", DateTime.Now, imageExtension); image.Data = imageBytes; image.Type = contentType; image.Category = category; db.Images.Add(image); db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Dodanie zdjęcia przebiegło pomyślnie."); return RedirectToAction("Index"); } catch (Exception e) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z zapisem danych. " + e.Message); } return View(image); }
public List <Sprite> GetImagesByCategory(ImageCategory category) { List <ImageInfo> images = Images.FindAll(x => x.category == category); List <Sprite> sprites = new List <Sprite>(); for (int i = 0; i < images.Count; i++) { sprites.Add(Resources.Load <Sprite>(images[i].name)); } return(sprites); }
ActionOutput IImageManager.AddUpdateImageCategory(AddUpdateAdminImageCategoryModel categoryModel) { var existingImageCategory = Context.ImageCategories.FirstOrDefault(z => z.ID == categoryModel.ID); if (existingImageCategory == null) { var newRecord = new ImageCategory(); var checkNameExist = Context.ImageCategories.FirstOrDefault(z => z.CategoryName.ToLower() == categoryModel.CategoryName.ToLower() && z.IsDeleted != true && z.ID != categoryModel.ID); if (checkNameExist != null) { return(new ActionOutput { Status = ActionStatus.Error, Message = "Image category name already exist." }); } newRecord = Mapper.Map <AddUpdateAdminImageCategoryModel, ImageCategory>(categoryModel); newRecord.ActivatedOn = DateTime.UtcNow; newRecord.AddedOn = DateTime.UtcNow; newRecord.IsDeleted = false; newRecord.IsActive = true; Context.ImageCategories.Add(newRecord); Context.SaveChanges(); return(new ActionOutput { Status = ActionStatus.Successfull, Message = "Image Category Added Sucessfully." }); } else { var checkNameExist = Context.ImageCategories.FirstOrDefault(z => z.CategoryName.ToLower() == categoryModel.CategoryName.ToLower() && z.IsDeleted != true && z.ID != categoryModel.ID); if (checkNameExist != null) { return(new ActionOutput { Status = ActionStatus.Error, Message = "Image category name already exist." }); } existingImageCategory = Mapper.Map <AddUpdateAdminImageCategoryModel, ImageCategory>(categoryModel, existingImageCategory); Context.SaveChanges(); return(new ActionOutput { Status = ActionStatus.Successfull, Message = "Image Category Updated Sucessfully." }); } }
public FileDetail(HttpPostedFileBase fileUpload, ImageCategory contentType = ImageCategory.Profile) { if (fileUpload != null) { Stream fileStream = fileUpload.InputStream; int fileLength = fileUpload.ContentLength; this.FileLength = fileLength; this.ContentType = contentType; this.FileContent = new byte[fileLength]; fileStream.Read(this.FileContent, 0, fileLength); } }
public async Task <int> CreateAsync(string imageFilePath, ImageCategory imageCategory) { var image = new Image { ImagePath = imageFilePath, ImageCategory = imageCategory }; _context.Images.Add(image); await _context.SaveChangesAsync(); return(image.ImageId); }
// GET: Admin/CategoryImage/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ImageCategory imageCategory = db.ImageCategories.Find(id); if (imageCategory == null) { return(HttpNotFound()); } return(View(imageCategory)); }
public int Create(string imageFilePath, ImageCategory imageCategory) { var image = new Image { ImagePath = imageFilePath, ImageCategory = imageCategory }; _context.Images.Add(image); _context.SaveChanges(); return(image.ImageId); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } ImageCategory = await _context.ImageCategory.FirstOrDefaultAsync(m => m.Id == id); if (ImageCategory == null) { return(NotFound()); } return(Page()); }
public IEnumerable <PictureViewModel> GetPictures(IRepository <Picture> pictures, string category) { ImageCategory enumCategory = (ImageCategory)0; if (Enum.IsDefined(typeof(ImageCategory), category)) { enumCategory = (ImageCategory)Enum.Parse(typeof(ImageCategory), category); } IEnumerable <PictureViewModel> hotelPictures = pictures .All() .Where(p => p.Category == enumCategory && p.IsDeleted == false) .To <PictureViewModel>() .ToList(); return(hotelPictures); }
public static ImageCategoryViewModel Map(ImageCategory category) { if (category == null) { return(new ImageCategoryViewModel()); } return(new ImageCategoryViewModel() { Id = category.Id, Description = category.Description, Name = category.Name, IsGallery = category.IsGallery, Link = category.CategoryUrl, IsBasket = category.IsBasket, Images = category.Images != null?category.Images.Select(ImageViewModel.Map).ToList() : null }); }
public ActionResult Edit(int id, [Bind(Include = "Id,Name,Description,Image")] ImageCategory imageCategory, HttpPostedFileBase Photo) { if (ModelState.IsValid) { ImageCategory selected = db.ImageCategories.SingleOrDefault(nt => nt.Id == id); if (Photo != null) { WebImage image = new WebImage(Photo.InputStream); FileInfo photoInfo = new FileInfo(Photo.FileName); string newPhoto = Guid.NewGuid().ToString() + photoInfo; image.Save("~/Uploads/ProjectImage/" + newPhoto); imageCategory.Image = "/Uploads/ProjectImage/" + newPhoto; } selected.Image = imageCategory.Image; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(imageCategory)); }
public ActionResult Create(ImageCategory imageCategory, IList <IFormFile> image, IFormCollection collection) { try { var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); imageCategory.DateCreated = DateTime.Now; imageCategory.DateLastModified = DateTime.Now; imageCategory.CreatedBy = signedInUserId; imageCategory.LastModifiedBy = signedInUserId; if (image.Count > 0) { foreach (var file in image) { var fileInfo = new FileInfo(file.FileName); var ext = fileInfo.Extension.ToLower(); var name = DateTime.Now.ToFileTime().ToString(); var fileName = name + ext; //var uploadedImage = _hostingEnv.WebRootPath + $@"\UploadedImage\ImageCategory\{fileName}"; var uploadedImage = new AppConfig().ImageCategoryPicture + fileName; using (var fs = System.IO.File.Create(uploadedImage)) { if (fs != null) { file.CopyTo(fs); fs.Flush(); imageCategory.FileName = fileName; } } } } _databaseConnection.ImageCategories.Add(imageCategory); _databaseConnection.SaveChanges(); //display notification TempData["display"] = "You have successfully added a new Image Category!"; TempData["notificationtype"] = NotificationType.Success.ToString(); return(RedirectToAction("Index")); } catch (Exception) { return(View()); } }
string shortenCategory(ImageCategory category) { if (category == ImageCategory.ContactProfile || category == ImageCategory.OpportunityProfile) { return("pi"); } else if (category == ImageCategory.Campaigns || category == ImageCategory.CampaignTemplateThumbnails) { return("ci"); } else if (category == ImageCategory.AccountLogo) { return("ai"); } else { throw new InvalidOperationException("Mentioned category of image is not defined." + category.ToString()); } }
// function to save image // parameters: File, Relative Path, Name public static string SaveImage(HttpPostedFileBase file, ImageCategory category, string name) { // check extension validity var extension = Path.GetExtension(file.FileName); if (IsValidExtension(extension)) { // compose path and save file var path = $"~/Images/{category.ToString()}"; var finalPath = Path.Combine(path, name + extension).Replace("\\", "/"); var rootPath = HostingEnvironment.MapPath(finalPath); file.SaveAs(rootPath); return(finalPath); } return(""); }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } ImageCategory = await _context.ImageCategory.FirstOrDefaultAsync(m => m.Id == id); CookieOptions option = new CookieOptions(); option.Expires = DateTime.Now.AddSeconds(60); Response.Cookies.Append("Category", ImageCategory.Name.ToLower(), option); if (ImageCategory == null) { return(NotFound()); } return(Page()); }
private ActionResult Set(ImageCategory category, int id) { var query = from i in db.Images where i.Category == category select i; var images = query.ToList(); if (images.Count() == 0) { return(HttpNotFound()); } SetImageViewModel setItemViewModel = new SetImageViewModel() { Images = images, Id = (int)id, Category = category }; return(View("Set", setItemViewModel)); }
public List <List <Sprite> > GetImagesByCategory(ImageCategory category, bool groupByID) { if (!groupByID) { return(null); } List <ImageInfo> images = Images.FindAll(x => x.category == category); List <List <Sprite> > sprites = new List <List <Sprite> >(); int index = images.Max(x => x.id); for (int i = 0; i < index; i++) { sprites.Add(new List <Sprite>()); } for (int i = 0; i < images.Count; i++) { sprites[images[i].id - 1].Add(Resources.Load <Sprite>(images[i].name)); } return(sprites); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } ImageCategory = await _context.ImageCategory.FindAsync(id); if (ImageCategory != null) { _context.ImageCategory.Remove(ImageCategory); await _context.SaveChangesAsync(); string webRoot = _hostEnvironment.WebRootPath; var path = Path.Combine(webRoot, $"img\\{ImageCategory.Name.ToLower()}"); if (Directory.Exists(path)) { Directory.Delete(path, true); } } return(RedirectToPage("./Index")); }
public string LoadCategories() { DataTable dt = new DataTable(); using (MySqlConnection cnn = new MySqlConnection(ConnectionStrings.MySqlConnectionString())) { cnn.Open(); using (var cmd = cnn.CreateCommand()) { cmd.CommandText = @"SELECT * FROM lockbusiness_categories ORDER BY category asc"; MySqlDataAdapter da = new MySqlDataAdapter(cmd); da.Fill(dt); } } JavaScriptSerializer serializer = new JavaScriptSerializer(); List<ImageCategory> listCategories = new List<ImageCategory>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ImageCategory objst = new ImageCategory(); objst.ID = dt.Rows[i]["id"].ToString(); objst.Name = dt.Rows[i]["category"].ToString(); listCategories.Insert(i, objst); } } return serializer.Serialize(listCategories); }
//public UploadFiles(ImageCategory category,params string[] keys) //{ // this.imageCategory = category; // //add value to keys // foreach (var item in keys) // { // this.keys.Add(item); // } //} public UploadFiles(ImageCategory category, string key) { this.imageCategory = category; //add value to keys this.key = key; }
public static FileDetail LoadImageFromPath(string importDirectory = "~/App_Data", string fileName = "noImage.png", ImageCategory imageCategory = ImageCategory.General) { byte[] imageData = null; var imagePath = Path.Combine(HttpContext.Current.Server.MapPath(importDirectory), fileName); if (File.Exists(imagePath)) { imageData = File.ReadAllBytes(imagePath); } return(new FileDetail { FileLength = imageData.Length, ContentType = imageCategory, FileContent = imageData }); }
public Sprite GetImageByCategory(ImageCategory category) { return(Resources.Load <Sprite>(Images.Find(x => x.category == category).name)); }
public AppraisalOutput processImageLatLon(string imageBase64, double?latitude, double?longitude, string deviceId, string userAgent) { AppraisalOutput appraisalOutput = new AppraisalOutput(); GoogleVisionApi googleVisionApi = new GoogleVisionApi(); PriceInput priceInput = new PriceInput(); ImageCategory imageCategory; string country; string countryCode; double? lat; double? lng; try { imageCategory = googleVisionApi.fetchCategoryForImage(imageBase64); } catch (Exception) { // imageBase64 = getImageAndConvertbase64(); // imageCategory = googleVisionApi.fetchCategoryForImage(imageBase64); imageCategory = new ImageCategory(); imageCategory.CategoryCode = -2; imageCategory.CategoryText = "Invalid Image"; } getAddressForLatLong(latitude ?? 0.0, longitude ?? 0.0); if (reverseGeoCodeResult.Country != "Switzerland") { country = "Switzerland"; countryCode = "CH"; priceInput.zip = appraisalOutput.zip = ConfigurationManager.AppSettings["DefaultZip"]; priceInput.town = appraisalOutput.town = ConfigurationManager.AppSettings["DefaultTown"]; //if country is not switzerland then attach time to street . priceInput.street = appraisalOutput.street = ConfigurationManager.AppSettings["DefaultStreet"] + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second; appraisalOutput.minappraisalValue = Convert.ToInt64(latitude.ToString().Replace(".", String.Empty)); appraisalOutput.maxappraisalValue = Convert.ToInt64(longitude.ToString().Replace(".", String.Empty)); lat = Convert.ToDouble(ConfigurationManager.AppSettings["DefaultLatitude"]); lng = Convert.ToDouble(ConfigurationManager.AppSettings["DefaultLongitude"]); } else { country = reverseGeoCodeResult.Country; countryCode = "CH"; priceInput.zip = appraisalOutput.zip = reverseGeoCodeResult.Zip; priceInput.town = appraisalOutput.town = reverseGeoCodeResult.Town; priceInput.street = appraisalOutput.street = reverseGeoCodeResult.Street; lat = (double)latitude; lng = (double)longitude; } if (imageCategory.CategoryCode != -1 && imageCategory.CategoryCode != -2) { getMicroRating(imageCategory.CategoryCode, lat ?? 0.0, lng ?? 0.0, countryCode); priceInput.qualityMicro = appraisalOutput.microRating = ratingResponse.results.microRatingClass1To5 ?? 3; } appraisalOutput.country = country; appraisalOutput.CatCode = imageCategory.CategoryCode; switch (imageCategory.CategoryCode) { case 5: priceInput.surfaceLiving = Convert.ToInt16(ConfigurationManager.AppSettings["A2SurfaceLivingDefault"]); //set default for A2 for Surface appraisalOutput.category = imageCategory.CategoryText; //" Single family House"; break; case 6: priceInput.surfaceLiving = Convert.ToInt16(ConfigurationManager.AppSettings["A3SurfaceLivingDefault"]);; appraisalOutput.category = imageCategory.CategoryText; //" Condominium"; break; case -1: case -2: appraisalOutput.category = imageCategory.CategoryText; //Set the first two labels that are returned by Google break; default: break; } if (imageCategory.CategoryCode != -1 && imageCategory.CategoryCode != -2) { CalculatePrice(priceInput, imageCategory.CategoryCode, appraisalOutput); } //Saving Property Details// try { PriceData priceData = MapPriceBuisnessDataToDatabaseModel(imageBase64, latitude, longitude, deviceId, appraisalOutput); SavePricePropertyDetails(priceData, userAgent); } catch (Exception ex) { RealEstateRepository realEstateRepository = new RealEstateRepository(); realEstateRepository.saveException(ex.Message, Convert.ToString(ex.InnerException), ex.StackTrace); return(appraisalOutput); } return(appraisalOutput); }
public DisplayImage(ImageCategory category) { this.category = category; }
private ActionResult Set(ImageCategory category, int id) { var query = from i in db.Images where i.Category == category select i; var images = query.ToList(); if (images.Count() == 0) { return HttpNotFound(); } SetImageViewModel setItemViewModel = new SetImageViewModel() { Images = images, Id = (int)id, Category = category }; return View("Set", setItemViewModel); }
public ActionResult Set(ImageCategory? category, int? id, int? imageId) { if (category == null || !Enum.IsDefined(typeof(ImageCategory), category)) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } if(category == ImageCategory.Item) { var query = from i in db.Items where i.Id == id select i; var item = query.FirstOrDefault(); if (item == null) { return HttpNotFound(); } if (imageId == null) { return Set(ImageCategory.Item, item.Id); } var query2 = from i in db.Images where i.ID == imageId select i; var image = query2.FirstOrDefault(); if (image == null) { return HttpNotFound(); } try { item.ImageId = (int)imageId; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Obrazek został pomyślnie przypisany do przedmiotu."); return RedirectToAction("Details", "Item", new { id = item.Id }); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd z przypisaniem obrazka do przedmiotu."); } return Set(ImageCategory.Item, item.Id); } else if (category == ImageCategory.Monster) { var query = from i in db.Monsters where i.Id == id select i; var monster = query.FirstOrDefault(); if (monster == null) { return HttpNotFound(); } if (imageId == null) { return Set(ImageCategory.Monster, monster.Id); } var query2 = from i in db.Images where i.ID == imageId select i; var image = query2.FirstOrDefault(); if (image == null) { return HttpNotFound(); } try { monster.ImageId = (int)imageId; db.Entry(monster).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Obrazek został pomyślnie przypisany do potwora."); return RedirectToAction("Details", "Monster", new { id = monster.Id }); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd z przypisaniem obrazka do potwora."); } return Set(ImageCategory.Monster, monster.Id); } else if (category == ImageCategory.Location) { var query = from i in db.Locations where i.ID == id select i; var location = query.FirstOrDefault(); if (location == null) { return HttpNotFound(); } if (imageId == null) { return Set(ImageCategory.Location, location.ID); } var query2 = from i in db.Images where i.ID == imageId select i; var image = query2.FirstOrDefault(); if (image == null) { return HttpNotFound(); } try { location.ImageId = (int)imageId; db.Entry(location).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Obrazek został pomyślnie przypisany do lokacji."); return RedirectToAction("Details", "Location", new { id = location.ID }); } catch (Exception) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd z przypisaniem obrazka do lokacji."); } return Set(ImageCategory.Location, location.ID); } return HttpNotFound(); }
public ActionResult Edit(int? id, HttpPostedFileBase file, ImageCategory category) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } var query = from i in db.Images where i.ID == id select i; var image = query.FirstOrDefault(); try { if (!Enum.IsDefined(typeof(ImageCategory), category)) { throw new Exception("Niewłaściwa Katygoria"); } if (file != null) { var fileName = Path.GetFileName(file.FileName); //nazwa pliku var imageName = Path.GetFileNameWithoutExtension(fileName); var imageExtension = ""; var contentLength = file.ContentLength; //wielkosc pliku var contentType = file.ContentType; //typ pliku byte[] imageBytes = new byte[contentLength - 1]; using (var binaryReader = new BinaryReader(file.InputStream)) { imageBytes = binaryReader.ReadBytes(file.ContentLength); } image.FileName = String.Format("{0:yyyyMMddHHmmss}.{1}", DateTime.Now, imageExtension); image.Data = imageBytes; image.Type = contentType; } image.Category = category; db.Entry(image).State = EntityState.Modified; db.SaveChanges(); FlashMessageHelper.SetMessage(this, FlashMessageType.Success, "Aktualizacja danych przebiegła pomyślnie."); return RedirectToAction("Index"); } catch (DbUpdateConcurrencyException) { FlashMessageHelper.SetMessage(this, FlashMessageType.Warning, "Dane zostały zaktualizowane przez inną osobę. Należy odświeżyć stronę w celu wczytania nowych danych."); } catch (Exception e) { FlashMessageHelper.SetMessage(this, FlashMessageType.Danger, "Wystąpił nieoczekiwany błąd związany z aktualizowaniem danych. " + e.Message); } return View(image); }