public SellProperty AddSellProperty(SellProperty sellProperty) { //string userId = "02e8959c-b441-4b51-89dc-92eea1bf2773"; //sellProperty.UserId = userId; DateTime currentTime = DateTime.UtcNow; sellProperty.ReopAddDate = currentTime; sellProperty.LastModified = currentTime; Repository.Add<SellProperty>(sellProperty); Repository.Save(); return sellProperty; }
public ActionResult Sell(FormCollection collection) { ViewBag.Messages = new List<string>(); ViewBag.Errors = new List<string>(); SellProperty sellProperty = new SellProperty(); sellProperty.PropertyStatus = "pending"; sellProperty.SellPropertyPhotos = new List<SellPropertyPhoto>(); SellPropertyPhoto sellPropertyPhoto1 = null; SellPropertyPhoto sellPropertyPhoto2 = null; SellPropertyPhoto sellPropertyPhoto3 = null; try { User user = GetUserFromCookie(); ViewBag.User = user; string userId = null; if (user != null) userId = user.UserId; else throw new UserNotFoundException("Seems you are not logged in."); HttpPostedFileBase image1 = Request.Files["uploadBtn"]; HttpPostedFileBase image2 = Request.Files["uploadBtn2"]; HttpPostedFileBase image3 = Request.Files["uploadBtn3"]; HttpPostedFileBase file = Request.Files["uploadBtn_file"]; string fileURL = ""; string fileName = ""; if ((image1 != null) && (image1.ContentLength > 0) && !string.IsNullOrEmpty(image1.FileName)) { if (HttpPostedFileBaseExtensions.IsImage(image1) == false) { ViewBag.Errors.Add("Please upload a valid image."); throw new Exception(); } if (HttpPostedFileBaseExtensions.IsImageSizeValid(image1) == false) { ViewBag.Errors.Add("Image must be smaller than 2 Mb."); throw new Exception(); } string extension = ".JPG"; if (string.IsNullOrWhiteSpace(image1.FileName) == false) { string[] fnParts = image1.FileName.Split('.'); extension = fnParts[fnParts.Length - 1]; } string aUrl = _servicesManager.FileStorage.UploadContentFile( string.Format("ui_{0}", Guid.NewGuid().ToString()), extension, image1.InputStream); // user.Photo = aUrl; sellPropertyPhoto1 = new SellPropertyPhoto(); sellPropertyPhoto1.PhotoUrl = aUrl; sellProperty.SellPropertyPhotos.Add(sellPropertyPhoto1); } if ((image2 != null) && (image2.ContentLength > 0) && !string.IsNullOrEmpty(image2.FileName)) { if (HttpPostedFileBaseExtensions.IsImage(image2) == false) { ViewBag.Errors.Add("Please upload a valid image."); throw new Exception(); } if (HttpPostedFileBaseExtensions.IsImageSizeValid(image2) == false) { ViewBag.Errors.Add("Image must be smaller than 2 Mb."); throw new Exception(); } string extension = ".JPG"; if (string.IsNullOrWhiteSpace(image2.FileName) == false) { string[] fnParts = image2.FileName.Split('.'); extension = fnParts[fnParts.Length - 1]; } string aUrl = _servicesManager.FileStorage.UploadContentFile( string.Format("ui_{0}", Guid.NewGuid().ToString()), extension, image2.InputStream); // user.Photo = aUrl; sellPropertyPhoto2 = new SellPropertyPhoto(); sellPropertyPhoto2.PhotoUrl = aUrl; sellProperty.SellPropertyPhotos.Add(sellPropertyPhoto2); } if ((image3 != null) && (image3.ContentLength > 0) && !string.IsNullOrEmpty(image3.FileName)) { if (HttpPostedFileBaseExtensions.IsImage(image3) == false) { ViewBag.Errors.Add("Please upload a valid image."); throw new Exception(); } if (HttpPostedFileBaseExtensions.IsImageSizeValid(image3) == false) { ViewBag.Errors.Add("Image must be smaller than 2 Mb."); throw new Exception(); } string extension = ".JPG"; if (string.IsNullOrWhiteSpace(image3.FileName) == false) { string[] fnParts = image3.FileName.Split('.'); extension = fnParts[fnParts.Length - 1]; } string aUrl = _servicesManager.FileStorage.UploadContentFile( string.Format("ui_{0}", Guid.NewGuid().ToString()), extension, image3.InputStream); // user.Photo = aUrl; sellPropertyPhoto3 = new SellPropertyPhoto(); sellPropertyPhoto3.PhotoUrl = aUrl; sellProperty.SellPropertyPhotos.Add(sellPropertyPhoto3); } if ((file != null) && (file.ContentLength > 0) && !string.IsNullOrEmpty(file.FileName)) { string extension = ".JPG"; if (string.IsNullOrWhiteSpace(file.FileName) == false) { string[] fnParts = file.FileName.Split('.'); extension = fnParts[fnParts.Length - 1]; fileName = file.FileName; } string aUrl = _servicesManager.FileStorage.UploadContentFile( string.Format("ui_{0}", Guid.NewGuid().ToString()), extension, file.InputStream); // user.Photo = aUrl; // sellPropertyPhoto1 = new SellPropertyPhoto(); // sellPropertyPhoto1.PhotoUrl = aUrl; // sellProperty.SellPropertyPhotos.Add(sellPropertyPhoto1); fileURL = aUrl; sellProperty.fileName = fileName; sellProperty.fileURL = fileURL; } string address = collection.Get("sell_address"); string city = collection.Get("sell_city"); string desiredSellingPrice = collection.Get("sell_desiredSellingPrice"); if ((address == null) || (address.Trim() == "")) return null; if ((city == null) || (city.Trim() == "")) return null; if ((desiredSellingPrice == null) || (desiredSellingPrice.Trim() == "")) return null; string zipcode = collection.Get("sell_zipcode"); string state = collection.Get("sell_state"); string beds = collection.Get("sell_beds"); string baths = collection.Get("sell_baths"); string halfBaths = collection.Get("sell_half_baths"); string type = collection.Get("sell_type"); string description = collection.Get("sell_description"); string condition = collection.Get("sell_condition"); string openHouse = collection.Get("sell_openHouse"); string sellShowtimeFromDay1 = collection.Get("sell_showtime_from_day1"); string sellShowtimeFromDay2 = collection.Get("sell_showtime_from_day2"); string sellShowtimeFromDay3 = collection.Get("sell_showtime_from_day3"); string sellShowtimeToDay1 = collection.Get("sell_showtime_to_day1"); string sellShowtimeToDay2 = collection.Get("sell_showtime_to_day2"); string sellShowtimeToDay3 = collection.Get("sell_showtime_to_day3"); string sellShowtimeFromTime1 = collection.Get("sell_showtime_from_time1"); string sellShowtimeToTime1 = collection.Get("sell_showtime_to_time1"); string sellShowtimeFromTime2 = collection.Get("sell_showtime_from_time2"); string sellShowtimeToTime2 = collection.Get("sell_showtime_to_time2"); string sellShowtimeFromTime3 = collection.Get("sell_showtime_from_time3"); string sellShowtimeToTime3 = collection.Get("sell_showtime_to_time3"); string customLabel1 = collection.Get("custom_label1"); string customLabel2 = collection.Get("custom_label2"); string customValue1 = collection.Get("custom_value1"); string customValue2 = collection.Get("custom_value2"); //Sstring custom // DateTime showTime1 = new DateTime( ); // TimeSpan showTime1 = new TimeSpan(); DayOfWeek FromDay1 = (DayOfWeek)DayOfWeekInt(sellShowtimeFromDay1); DayOfWeek FromDay2 = (DayOfWeek)DayOfWeekInt(sellShowtimeFromDay2); DayOfWeek FromDay3 = (DayOfWeek)DayOfWeekInt(sellShowtimeFromDay3); DayOfWeek ToDay1 = (DayOfWeek)DayOfWeekInt(sellShowtimeToDay1); DayOfWeek ToDay2 = (DayOfWeek)DayOfWeekInt(sellShowtimeToDay2); DayOfWeek ToDay3 = (DayOfWeek)DayOfWeekInt(sellShowtimeToDay3); sellProperty.FromTime1 = TimeSpan.Parse(sellShowtimeFromTime1); sellProperty.ToTime1 = TimeSpan.Parse(sellShowtimeToTime1); sellProperty.FromTime2 = TimeSpan.Parse(sellShowtimeFromTime2); sellProperty.ToTime2 = TimeSpan.Parse(sellShowtimeToTime2); sellProperty.FromTime3 = TimeSpan.Parse(sellShowtimeFromTime3); sellProperty.ToTime3 = TimeSpan.Parse(sellShowtimeToTime3); sellProperty.FromDay1 = FromDay1; sellProperty.FromDay2 = FromDay2; sellProperty.FromDay3 = FromDay3; sellProperty.FullStreetAddress = address; sellProperty.City = city; sellProperty.State = state; if ((zipcode != null) && (zipcode.Trim() != "")) sellProperty.PostalCode = long.Parse(zipcode); try { int temp = 0; if(Int32.TryParse(beds, out temp)) sellProperty.Beds = Int32.Parse(beds); if (Int32.TryParse(baths, out temp)) sellProperty.Baths = Int32.Parse(baths); if (Int32.TryParse(halfBaths, out temp)) sellProperty.BathsHalf = Int32.Parse(halfBaths); } catch (Exception exc) { Console.WriteLine(exc.StackTrace); } sellProperty.PropertyType = type; sellProperty.HomeDescription = description; sellProperty.Condition = condition; sellProperty.DesiredSellingPrice = desiredSellingPrice; if (openHouse.Equals("true")) sellProperty.OpenHouseFlag = true; else if (openHouse.Equals("false")) sellProperty.OpenHouseFlag = false; sellProperty.CustomLabel1 = customLabel1; sellProperty.CustomLabel2 = customLabel2; sellProperty.CustomValue1 = customValue1; sellProperty.CustomValue2 = customValue2; sellProperty.UserId = userId; _userManager.AddSellProperty(sellProperty); ViewBag.Messages.Add("Property saved successfully."); } catch (Exception e) { ViewBag.Errors.Add("There was an error. Please try later."); //ViewBag.Errors.Add("[Detail : " + e.Message + "]"); } return View("sell"); }