public static Common.Image LoadImage(Guid imageGuid) { Business.Image imageController = new Business.Image(); Common.Image images = new Common.Image(); imageController.Load(imageGuid, images); return(images); }
public Task <List <BaseObject> > GenModels(ModelStateDictionary modelState, List <IFormFile> files, string description, string title, string attribution, int?relatedPostId, Visibility visibility) { return(Task.FromResult(files.Select((f, i) => { if (f.Length == 0) { modelState.AddModelError("Files", $"File {f.FileName} is empty"); } else if (f.Length > _settings.Site.MaxFileSize) { modelState.AddModelError("Files", $"File {f.FileName} too large ({f.Length} is over limit of {_settings.Site.MaxFileSize})"); } else if (!System.IO.Path.HasExtension(f.FileName)) { modelState.AddModelError("Files", $"File missing extension: {f.FileName}"); } else { var mediaType = ResolveMediaType(f.FileName); if (mediaType.HasValue) { Document doc = null; switch (mediaType.Value) { case CommonMediaType.Audio: doc = new Audio(); break; case CommonMediaType.Photo: doc = new Common.Image(); break; case CommonMediaType.Video: doc = new Audio(); break; } doc.url = new Link { content = Path.ChangeExtension(System.IO.Path.GetTempFileName(), Path.GetExtension(f.FileName)) }; doc.summary = string.IsNullOrEmpty(description) ? f.FileName : description; doc.name = string.IsNullOrWhiteSpace(title) ? f.FileName : title; if (string.IsNullOrWhiteSpace(attribution)) { doc.attributedTo.Add(new Note { content = attribution }); } // doc.mediaType = mediaType.Value; // doc.size = f.Length < Int32.MaxValue ? (int) f.Length : -1; // OriginalName = f.FileName, // SizeBytes = f.Length < Int32.MaxValue ? (int) f.Length : -1, // RelatedPostId = RelatedPostId, // UserId = user.UserId, // Visibility = Visibility, return doc; } else { modelState.AddModelError("Files", $"Unsupported file type: {f.FileName}"); } } return null; }).Cast <BaseObject>().ToList())); }
//public DataTable GetAllImage(Guid userGuid) //{ // return base.FetchSPDataTable("GetAllImage", "@UserGuid", userGuid); //} public bool Update(Common.Image image) { return(base.ExecuteSPCommand("Update", "@Guid", image.ImageGuid, "@DataGuid", image.DataGuid, "@Title", image.Title, "@Description", image.Description, "@ImagePath", image.ImagePath)); }
private Post GetSavePost() { Post saveItem = new Post(); saveItem.PersonName = txtPersonName.Text; saveItem.PhoneNumber = txtPhoneNumber.Text; saveItem.Email = txtEmail.Text; saveItem.CountryId = 232; saveItem.CityId = Convert.ToInt32(cbbCity.SelectedValue); saveItem.DistrictId = Convert.ToInt32(cbbDistrict.SelectedValue); saveItem.Address = txtAddress.Text; saveItem.RoomTypeId = Convert.ToInt32(cbbRoomType.SelectedValue); saveItem.MeterSquare = Convert.ToDecimal(txtMeterSQuare.Value); saveItem.AvailableRooms = txtAvailableRooms.Value.HasValue ? Convert.ToInt32(txtAvailableRooms.Value) : 1; saveItem.Price = Convert.ToDecimal(txtPrice.Value); saveItem.Description = txtDescription.Text; saveItem.PostTypeId = this.PostType; if (this.PostType == (int)PostTypes.StayWith) { saveItem.Gender = radMale.Checked ? 1 : 0; } else if (this.PostType == (int)PostTypes.House) { saveItem.RealestateTypeId = Convert.ToInt32(cbbRealestateType.SelectedValue);; } saveItem.ImageList = new List <Common.Image>(); int displayIndex = 1; foreach (UploadedFile file in radUploadMulti.UploadedFiles) { string fileName = file.GetName(); System.Web.UI.WebControls.Image imageSource = new System.Web.UI.WebControls.Image(); Stream imageStream = file.InputStream; int bufferSize = Convert.ToInt32(imageStream.Length); byte[] byteArray = new byte[bufferSize]; imageStream.Read(byteArray, 0, bufferSize); MemoryStream resizedStream = UtilityHelper.ResizeFromStream(400, imageStream); Common.Image newImage = new Common.Image(); newImage.ImageContent = byteArray; newImage.ImageSmallContent = resizedStream.ToArray();; newImage.DisplayIndex = displayIndex++; newImage.ImageTypeId = (int)Common.ImageType.Room; newImage.FileName = fileName; newImage.CreatedBy = newImage.UpdatedBy = saveItem.PersonName; saveItem.ImageList.Add(newImage); } saveItem.CreatedBy = saveItem.UpdatedBy = saveItem.PersonName; return(saveItem); }
private void InitializePage() { btnSave.Attributes["onclick"] = "return validateRequiredFields();"; btnSave.Text = Language.GetString(btnSave.Text); btnCancel.Text = Language.GetString(btnCancel.Text); drpContent.DataSource = Facade.Data.GetUserData(UserGuid); drpContent.DataTextField = "Title"; drpContent.DataValueField = "Guid"; drpContent.DataBind(); drpContent.Items.Insert(0, new ListItem(string.Empty, string.Empty)); if (ActionType == "edit") { Common.Image image = Facade.Image.LoadImage(ImageGuid); txtTitle.Text = image.Title; txtDescription.Text = image.Description; hdnImagePath.Value = image.ImagePath; drpContent.SelectedValue = image.DataGuid.ToString(); } }
private Post GetSavePost() { Post saveItem = ViewState["CurrentPost"] as Post; int displayIndex = 1; if (saveItem == null) { saveItem = new Post(); saveItem.ImageList = new List<Common.Image>(); saveItem.PostTypeId = (int)PostTypes.Room; saveItem.CountryId = 232; } else if (saveItem.ImageList != null) { int? max = saveItem.ImageList.Max(i => i.DisplayIndex); displayIndex = (max.HasValue ? max.Value : 0) + 1; } saveItem.PersonName = txtPersonName.Text; saveItem.PhoneNumber = txtPhoneNumber.Text; saveItem.Email = txtEmail.Text; saveItem.CityId = Convert.ToInt32(cbbCity.SelectedValue); saveItem.DistrictId = Convert.ToInt32(cbbDistrict.SelectedValue); saveItem.Address = txtAddress.Text; saveItem.MeterSquare = Convert.ToDecimal(txtMeterSQuare.Value); saveItem.AvailableRooms = txtAvailableRooms.Value.HasValue ? Convert.ToInt32(txtAvailableRooms.Value) : 1; saveItem.Price = Convert.ToDecimal(txtPrice.Value); saveItem.Description = txtDescription.Text; saveItem.PostTypeId = GetPostTypeId(); if (saveItem.PostTypeId == (int)PostTypes.Room) { saveItem.RoomTypeId = Convert.ToInt32(cbbRoomType.SelectedValue); } if (saveItem.PostTypeId == (int)PostTypes.StayWith) { saveItem.RoomTypeId = Convert.ToInt32(cbbRoomType.SelectedValue); saveItem.Gender = radMale.Checked ? 1 : 0; } else if (saveItem.PostTypeId == (int)PostTypes.House) { saveItem.Gender = radMale.Checked ? 1 : 0; saveItem.RealestateTypeId = Convert.ToInt32(cbbRealestateType.SelectedValue); ; } foreach (UploadedFile file in radUploadMulti.UploadedFiles) { string fileName = file.GetName(); System.Web.UI.WebControls.Image imageSource = new System.Web.UI.WebControls.Image(); Stream imageStream = file.InputStream; int bufferSize = Convert.ToInt32(imageStream.Length); byte[] byteArray = new byte[bufferSize]; imageStream.Read(byteArray, 0, bufferSize); MemoryStream resizedStream = UtilityHelper.ResizeFromStream(400, imageStream); Common.Image newImage = new Common.Image(); newImage.ImageContent = byteArray; newImage.ImageSmallContent = resizedStream.ToArray(); ; newImage.DisplayIndex = displayIndex++; newImage.ImageTypeId = (int)Common.ImageType.Room; newImage.FileName = fileName; newImage.CreatedBy = newImage.UpdatedBy = saveItem.PersonName; saveItem.ImageList.Add(newImage); } saveItem.CreatedBy = saveItem.UpdatedBy = saveItem.PersonName; return saveItem; }
protected void btnSave_Click(object sender, EventArgs e) { Common.Image image = new Common.Image(); try { var domain = Helper.GetHostOfDomain(Request.Url.Authority); string uploadTarget = Server.MapPath(string.Format("~/Images/GalleryImage/{0}/", domain)); List <string> lstValidExtention = new List <string>(); lstValidExtention.Add(".jpg"); lstValidExtention.Add(".jpeg"); lstValidExtention.Add(".png"); lstValidExtention.Add(".gif"); lstValidExtention.Add(".bmp"); image.GalleryImageGuid = GalleryImageGuid; image.DataGuid = Helper.GetGuid(drpContent.SelectedValue); image.Title = txtTitle.Text; image.Description = txtDescription.Text; image.CreateDate = DateTime.Now; image.ImagePath = hdnImagePath.Value; image.IsActive = true; if (!Directory.Exists(uploadTarget)) { Directory.CreateDirectory(uploadTarget); } if (uploadImage.HasFile) { string fileExtention = Path.GetExtension(uploadImage.PostedFile.FileName).ToLower(); if (!lstValidExtention.Contains(fileExtention)) { throw new Exception((Language.GetString("InvalidFileExtension"))); } string pic = uploadImage.PostedFile.FileName; uploadImage.SaveAs(uploadTarget + pic); image.ImagePath = pic; } if (image.HasError) { throw new Exception(image.ErrorMessage); } switch (ActionType) { case "insert": if (!Facade.Image.Insert(image)) { throw new Exception(Language.GetString("ErrorRecord")); } break; case "edit": image.ImageGuid = ImageGuid; if (!Facade.Image.Update(image)) { throw new Exception(Language.GetString("ErrorRecord")); } break; } Response.Redirect(string.Format("/PageLoader.aspx?c={0}&GalleryGuid={1}", Helper.Encrypt((int)Arad.SMS.Gateway.Business.UserControls.UI_Images_Image, Session), GalleryImageGuid)); } catch (Exception ex) { ShowMessageBox(ex.Message, string.Empty, "danger"); } }
public static bool Update(Common.Image image) { Business.Image imageController = new Business.Image(); return(imageController.Update(image)); }
public static bool Insert(Common.Image images) { Business.Image imageController = new Business.Image(); return(imageController.Insert(images) != Guid.Empty ? true : false); }