public ActionResult Create(Location location, IFormCollection collection) { try { var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); location.DateCreated = DateTime.Now; location.DateLastModified = DateTime.Now; location.CreatedBy = signedInUserId; location.LastModifiedBy = signedInUserId; _databaseConnection.Locations.Add(location); _databaseConnection.SaveChanges(); if (collection != null && collection["Image"] != "" && collection["Image"] == "Redirect") { ViewBag.LocationId = new SelectList( _databaseConnection.Locations.Where(n => n.CreatedBy == signedInUserId).ToList(), "LocationId", "Name"); return(PartialView("Partials/_PartialImageLocation")); } //display notification TempData["display"] = "You have successfully added a new Location!"; TempData["notificationtype"] = NotificationType.Success.ToString(); return(RedirectToAction("Index")); } catch (Exception) { return(View()); } }
public ActionResult Create(ImageSubCategory imageSubCategory, IFormCollection collection) { try { // TODO: Add insert logic here var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); imageSubCategory.ImageCategoryId = Convert.ToInt64(collection["CategoryId"]); imageSubCategory.DateCreated = DateTime.Now; imageSubCategory.DateLastModified = DateTime.Now; imageSubCategory.CreatedBy = signedInUserId; imageSubCategory.LastModifiedBy = signedInUserId; _databaseConnection.ImageSubCategories.Add(imageSubCategory); _databaseConnection.SaveChanges(); //display notification TempData["display"] = "You have successfully added a new Image Sub-Category!"; TempData["notificationtype"] = NotificationType.Success.ToString(); return(RedirectToAction("Index", new{ id = imageSubCategory.ImageCategoryId })); } catch { return(View()); } }
public ActionResult Create(Advertisement advertisement, IList <IFormFile> image, IFormCollection collection) { try { var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); advertisement.DateCreated = DateTime.Now; advertisement.DateLastModified = DateTime.Now; advertisement.CreatedBy = signedInUserId; advertisement.LastModifiedBy = signedInUserId; if (_databaseConnection.Advertisements .Where(n => n.EndDate > advertisement.StartDate && n.PageCategory == advertisement.PageCategory) .ToList().Count <= 0) { 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 = new AppConfig().AdvertPicture + fileName; using (var fs = System.IO.File.Create(uploadedImage)) { if (fs != null) { file.CopyTo(fs); fs.Flush(); advertisement.File = fileName; } } } } _databaseConnection.Advertisements.Add(advertisement); _databaseConnection.SaveChanges(); //display notification TempData["display"] = "You have successfully added a new Advertisement to Camerack!"; TempData["notificationtype"] = NotificationType.Success.ToString(); return(RedirectToAction("Index")); } //display notification TempData["display"] = "The advert cannot be scheduled for the category at the set time" + ", check the category and time constraints!"; TempData["notificationtype"] = NotificationType.Error.ToString(); return(RedirectToAction("Index")); } catch (Exception) { return(View()); } }
public ActionResult Create(HeaderImage headerImage, IList <IFormFile> image, IFormCollection collection) { try { var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); headerImage.DateCreated = DateTime.Now; headerImage.DateLastModified = DateTime.Now; headerImage.CreatedBy = signedInUserId; headerImage.LastModifiedBy = signedInUserId; if (_databaseConnection.HeaderImages .Where(n => n.PageCategory == headerImage.PageCategory) .ToList().Count <= 0) { 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 = new AppConfig().HeaderPicture + fileName; using (var fs = System.IO.File.Create(uploadedImage)) { if (fs != null) { file.CopyTo(fs); fs.Flush(); headerImage.File = fileName; } } } } _databaseConnection.HeaderImages.Add(headerImage); _databaseConnection.SaveChanges(); //display notification TempData["display"] = "You have successfully added a new Header Image!"; TempData["notificationtype"] = NotificationType.Success.ToString(); return(RedirectToAction("Index")); } //display notification TempData["display"] = "The Header Image for the category Cannot be duplicated as it already exist!"; TempData["notificationtype"] = NotificationType.Error.ToString(); return(RedirectToAction("Index")); } catch (Exception) { return(View()); } }
/// <summary> /// The method returns a single images via a json object /// </summary> /// <param name="id"></param> /// <returns></returns> public JsonResult UpdateAdCount(long id) { var ad = _databaseConnection.Advertisements.Find(id); ad.AdClick = ad.AdClick + 1; _databaseConnection.Entry(ad).State = EntityState.Modified; _databaseConnection.SaveChanges(); return(Json(ad)); }
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()); } }
public ActionResult UserBank(UserBank userBank) { try { //populate object and save transaction var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); userBank.LastModifiedBy = signedInUserId; userBank.DateLastModified = DateTime.Now; _databaseConnection.Entry(userBank).State = EntityState.Modified; _databaseConnection.SaveChanges(); if (string.IsNullOrEmpty(userBank.AccountName) || userBank.BankId <= 0 || string.IsNullOrEmpty(userBank.AccountName) && HttpContext.Session.GetString("UserBank") == null) { var bankString = JsonConvert.SerializeObject(userBank); HttpContext.Session.SetString("UserBank", bankString); } else { HttpContext.Session.Remove("UserBank"); } //display notification TempData["display"] = "You have successfully updated your bank information"; TempData["notificationtype"] = NotificationType.Success.ToString(); return(RedirectToAction("Profile")); } catch (Exception ex) { //display notification TempData["display"] = ex.ToString(); TempData["notificationtype"] = NotificationType.Error.ToString(); return(View(userBank)); } }
public IActionResult Faq(Faq faq) { var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); faq.DateLastModified = DateTime.Now; faq.LastModifiedBy = signedInUserId; _databaseConnection.Entry(faq).State = EntityState.Modified; _databaseConnection.SaveChanges(); TempData["display"] = "You have successfully modified the FAQ!"; TempData["notificationtype"] = NotificationType.Success.ToString(); return(RedirectToAction("Dashboard", "Home")); }
public PartialViewResult RateImage(IFormCollection collection, ImageAction action) { var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); action.Action = "Rating"; action.ActionDate = DateTime.Now; action.AppUserId = signedInUserId; action.OwnerId = signedInUserId; action.ImageId = Convert.ToInt64(collection["ImageId"]); action.Rating = Convert.ToInt64(collection["rating"]); action.ClientId = new AppConfig().ClientId; if (_databaseConnection.ImageActions .Where(n => n.ImageId == action.ImageId && n.AppUserId == action.AppUserId).ToList().Count <= 0) { _databaseConnection.Add(action); _databaseConnection.SaveChanges(); } var image = _databaseConnection.Images.SingleOrDefault(n => n.ImageId == action.ImageId); var appTransport = new AppTransport { AppUsers = _users, Images = _databaseConnection.Images.ToList(), ImageActions = _databaseConnection.ImageActions.ToList(), Image = image, AppUser = _users.SingleOrDefault(n => n.AppUserId == signedInUserId) }; return(PartialView("Partials/_PartialRating", appTransport)); }
public async Task <IActionResult> Dashboard() { AppTransport appTransport = null; if (HttpContext.Session.GetString("StudioLoggedInUser") != null && HttpContext.Session.GetString("StudioLoggedInUserId") != null) { var signedInUserId = Convert.ToInt64(HttpContext.Session.GetString("StudioLoggedInUserId")); var userString = HttpContext.Session.GetString("StudioLoggedInUser"); _appUser = JsonConvert.DeserializeObject <AppUser>(userString); //update keys var updatedKeys = await new AppUserFactory().UpdateAccountActivationAccessKey( new AppConfig().UpdateAccountActivationAccessKey, _appUser.AppUserId); if (updatedKeys.AppUserAccessKeyId > 0) { //display notification TempData["display"] = "Welcome back " + _appUser.Name + " our awesome photographer!"; TempData["notificationtype"] = NotificationType.Success.ToString(); } //validate bank details if (_appUser != null && _appUser.Role.UploadImage) { if (_databaseConnection.UserBanks.Where(n => n.CreatedBy == _appUser.AppUserId).ToList().Count <= 0) { //populate and save bank transaction var newUserBank = new UserBank { CreatedBy = _appUser.AppUserId, LastModifiedBy = _appUser.AppUserId, DateCreated = DateTime.Now, DateLastModified = DateTime.Now }; _databaseConnection.UserBanks.Add(newUserBank); _databaseConnection.SaveChanges(); } else { var userBank = _databaseConnection.UserBanks.SingleOrDefault(n => n.CreatedBy == _appUser.AppUserId); if (userBank != null && (string.IsNullOrEmpty(userBank.AccountName) || userBank.BankId <= 0 || string.IsNullOrEmpty(userBank.AccountName) && HttpContext.Session.GetString("UserBank") == null)) { var bankString = JsonConvert.SerializeObject(userBank); HttpContext.Session.SetString("UserBank", bankString); } else { HttpContext.Session.Remove("UserBank"); } } } //store data temporarily, based on the user role if (_appUser != null && _appUser.Role.ManageImages) { appTransport = new AppTransport { Images = _databaseConnection.Images.ToList(), Cameras = _databaseConnection.Cameras.ToList(), Locations = _databaseConnection.Locations.ToList(), Orders = new OrderFactory().GetAllOrdersAsync(new AppConfig().FetchOrdersUrl).Result.ToList(), Payments = new OrderFactory().GetAllPaymentsAsync(new AppConfig().FetchPaymentsUrl).Result .ToList(), ImageDownloads = new ImageFactory().GetAllDownloads(new AppConfig().GetImageDownloadsUrl).Result, AppUser = _appUser }; } if (_appUser != null && _appUser.Role.UploadImage) { appTransport = new AppTransport { Images = _databaseConnection.Images.Where(n => n.AppUserId == signedInUserId).ToList(), Cameras = _databaseConnection.Cameras .Where(n => n.CreatedBy == signedInUserId).ToList(), Locations = _databaseConnection.Locations .Where(n => n.CreatedBy == signedInUserId).ToList(), Orders = new OrderFactory().GetAllOrdersAsync(new AppConfig().FetchOrdersUrl) .Result.Where(n => n.CreatedBy == signedInUserId).ToList(), Payments = new OrderFactory().GetAllPaymentsAsync(new AppConfig().FetchPaymentsUrl).Result .Where(n => n.AppUserId == signedInUserId) .ToList(), ImageDownloads = new ImageFactory().GetAllDownloads(new AppConfig().GetImageDownloadsUrl).Result, AppUser = _appUser }; } //validate mapping if (appTransport != null) { appTransport.AppUsers = new AppUserFactory().GetAllUsers(new AppConfig().FetchUsersUrl).Result .ToList(); } return(View(appTransport)); } return(Redirect("https://camerack.com/Account/Login?returnUrl=sessionExpired")); }