public async Task <IActionResult> Create(CreatePackageViewModel model) { if (ModelState.IsValid) { var user = this.userManager.Users.FirstOrDefault(u => u.UserName == model.Recipient); var package = new Package() { Description = model.Description, Weight = model.Weight, Status = Status.Pending, EstimatedDeliveryDate = null, RecipientId = user.Id, ShippingAddress = model.ShippingAddress }; user.Packages.Add(package); await this.userManager.UpdateAsync(user); return(this.RedirectToAction("Index", "Home")); } return(this.View()); }
public IActionResult Create(CreatePackageViewModel model) { var user = getUserService.GetUser(model.Recepient); if (user == null) { return(this.BadRequest("Invalid recipient username.")); } model.Status = Status.Pending; Package package = new Package() { Description = model.Description, RecipientId = user.Id, Recipient = user, ShippingAddress = model.ShippingAddress, Status = model.Status, Weight = model.Weight, DeliveryDate = null, }; this.packageService.AddPackage(package); return(this.Redirect($"/Packages/Details?id={package.Id}")); }
public ActionResult Edit(int id) { var data = db.Packages.Find(id); if (ViewBag.StudioID != data.studioid) { return(RedirectToAction("packagehome")); } if (!data.Studio.UserStudios.Any(x => x.userid == UserAuthentication.Identity().id)) { return(RedirectToAction("Error500", "Home", new { errormsg = "You picked the wrong studio Fool!" })); } var edit = new CreatePackageViewModel { id = data.id, depoprice = data.depositprice, details = data.details, price = data.price, studioid = data.studioid.Value, name = data.name, images = data.PackageImages.ToList(), ImgName = data.PackageImages.FirstOrDefault().ImageName }; return(View("editpackage", edit)); }
public async Task <IActionResult> Create(CreatePackageViewModel vm) { if (ModelState.IsValid) { ApplicationUser currentUser = await _userManagerService.FindByNameAsync(User.Identity.Name); Provider currentProvider = _providerRepo.GetSingle(p => p.UserId == currentUser.Id); string thumbnailUrl = ""; if (vm.ThumbnailUrl != null && vm.ThumbnailUrl != "") { thumbnailUrl = $@"\images\" + currentProvider.UserId + "\\" + vm.ThumbnailUrl; } Package newPackage = new Package { ProviderId = vm.ProviderId, Name = vm.Name, ThumbnailUrl = thumbnailUrl, Location = vm.Location, Description = vm.Description, Price = vm.Price, IsActive = vm.IsActive }; _packageRepo.Create(newPackage); return(RedirectToAction("Index")); } return(View(vm)); }
public IHttpResponse Create(CreatePackageViewModel view) { //Validate if (view.Description == null || view.Recipient == null || view.ShippingAddress == null || view.Weight == null) { return(BadRequestErrorWithView("Invalid package data!")); } var user = this.Db.Users.FirstOrDefault(u => u.Username == view.Recipient); if (user == null) { return(BadRequestErrorWithView("Invalid package data!")); } var package = new Package { Status = Status.Pending, EstimatedDeliveryDate = null, Description = view.Description, ShippingAddress = view.ShippingAddress, Weight = float.Parse(view.Weight), UserId = user.Id }; this.Db.Packages.Add(package); this.Db.SaveChanges(); return(this.Redirect($"/Packages/Details?id={package.Id}")); }
public IActionResult CreatePackage(CreatePackageViewModel packageViewModel) { if (!ModelState.IsValid) { var users = _userService.GetUsers(); var createPackageViewModel = new CreatePackageViewModel { Users = users }; return(this.View(createPackageViewModel)); } var userId = Request.Form["UserId"]; var package = new Package { Description = packageViewModel.Description, Weight = packageViewModel.Weight, ShippingAddreess = packageViewModel.ShippingAddress, RecipientId = userId }; _packageService.AddPackage(package); return(RedirectToAction("PendingPackages", "Package")); }
public IActionResult Create() { var model = new CreatePackageViewModel { Couriers = _courierService.GetCouriers() }; return(View(model)); }
public IActionResult CreatePackage() { var users = _userService.GetUsers(); var createPackageViewModel = new CreatePackageViewModel { Users = users }; return(this.View(createPackageViewModel)); }
public IActionResult Create() { var viewModel = new CreatePackageViewModel(); viewModel.Recipients = this.dbService.Db().Users.Select(u => new BaseUserViewModel() { Username = u.UserName }).ToList(); return(this.View(viewModel)); }
public async Task <IActionResult> Create(CreatePackageViewModel model) { if (!ModelState.IsValid) { return(View(model)); } await _packageService.Create(model); return(RedirectToAction("Index", "Home")); }
public IActionResult Create(CreatePackageViewModel model) { if (!this.ModelState.IsValid) { return(this.Redirect("/Packages/Create")); } if (!this.packageService.CreatePackage(model.Description, model.Weight, model.ShippingAddress, model.RecipientName)) { return(this.Redirect("/Packages/Create")); } return(this.Redirect("/Packages/Pending")); }
public HttpResponse Create(CreatePackageViewModel input) { if (!this.IsUserLoggedIn()) { return(this.Redirect("/")); } if (input.Description.Length < 5 || input.Description.Length > 20) { return(this.Redirect("Create")); } this.packagesServer.CreatePackage(input.Description, input.Weight, input.ShippingAddress, input.RecipientName); return(this.Redirect("/")); }
public IActionResult Create(CreatePackageViewModel addPackage) { Package package = new Package { Description = addPackage.Description, Recipient = this.context.Users.SingleOrDefault(user => user.UserName == addPackage.Recipients), ShippingAddress = addPackage.ShippingAddress, Weight = addPackage.Weight, Status = this.context.PackageStatuses.SingleOrDefault(status => status.Name == "Pending") }; this.context.Packages.Add(package); this.context.SaveChanges(); return(this.Redirect("/Package/Pending")); }
public ActionResult Create(CreatePackageViewModel data) { if (!db.UserStudios.ToList().Any(x => x.userid == UserAuthentication.Identity().id&& x.studioid == data.studioid)) { return(RedirectToAction("Error500", "Home", new { errormsg = "You picked the wrong studio Fool!" })); } if (ModelState.IsValid) { try { if (data.price < data.depoprice || data.price <= 0 || data.depoprice < 0) { TempData["error"] = "Invalid price setting"; return(View("editpackage", data)); } var pack = new Package { depositprice = data.depoprice, details = string.IsNullOrWhiteSpace(data.details) ? null : data.details, name = data.name, price = data.price, studioid = data.studioid, status = "Enabled" }; if (!string.IsNullOrWhiteSpace(data.ImgName)) { PackageImage package = new PackageImage { ImageName = data.ImgName }; pack.PackageImages.Add(package); } db.Packages.Add(pack); db.SaveChanges(); return(RedirectToAction("PackageHome")); } catch (Exception e) { return(RedirectToAction("Error500", "Home", new { errormsg = e.Message })); } } return(View("editpackage", data)); }
public async Task <IActionResult> Create(int id) { var loggedUser = await _userManagerService.FindByNameAsync(User.Identity.Name); CreatePackageViewModel vm = new CreatePackageViewModel { UserId = loggedUser.Id, CatList = _catRepo.GetAll() }; if (id != 0) { vm.CategoryId = id; } return(View(vm)); }
public async Task <IActionResult> Create(CreatePackageViewModel vm, IFormFile ImgPath) { var loggedUser = await _userManagerService.FindByNameAsync(User.Identity.Name); if (ModelState.IsValid) { Package p = new Package { CategoryId = vm.CategoryId, Name = vm.Name, Location = vm.Location, Description = vm.Description, Price = vm.Price, IsActive = vm.IsActive, UserId = loggedUser.Id }; string uploadPath = Path.Combine(_environment.WebRootPath, "Uploads"); uploadPath = Path.Combine(uploadPath, User.Identity.Name); Directory.CreateDirectory(Path.Combine(uploadPath, p.Name)); if (ImgPath != null) { string fileName = Path.GetFileName(ImgPath.FileName); using (FileStream fs = new FileStream(Path.Combine(uploadPath, p.Name, fileName), FileMode.Create)) { ImgPath.CopyTo(fs); } p.ImgPath = Path.Combine(User.Identity.Name, p.Name, fileName); } else { p.ImgPath = ""; } _packRepo.Create(p); return(RedirectToAction("Index", "Provider", new { id = vm.UserId })); } vm.CatList = _catRepo.GetAll(); return(View(vm)); }
public IHttpResponse Create(CreatePackageViewModel viewModel) { var recipient = Db.Users.FirstOrDefault(x => x.Username == viewModel.Recipient); var package = new Package { Description = viewModel.Description, RecipientId = recipient.Id, Weight = viewModel.Weight, ShippingAddress = viewModel.ShippingAddress, Status = Status.Pending, }; Db.Packages.Add(package); Db.SaveChanges(); return(this.Redirect("/Home/Index")); }
public IHttpResponse Create(CreatePackageViewModel model) { var recipient = this.Db.Users .FirstOrDefault(x => x.Username == this.User.Username); var package = new Package { Description = model.Description, Weight = model.Weight, ShippingAddress = model.ShippingAddress, Recipient = recipient, Status = Status.Pending }; this.Db.Packages.Add(package); this.Db.SaveChanges(); return(this.Redirect("/")); }
public async Task Create(CreatePackageViewModel model) { var package = new Package() { Address = model.Address, CourierId = model.CourierId, CustomerEmail = model.Email, Status = PackageStatus.InMagazine.ToString() }; if (model.CourierId == 0) { package.CourierId = null; } await _dbContext.Packages.AddAsync(package); await _dbContext.SaveChangesAsync(); CreateTrackingMail(package.Id, package.CustomerEmail); }
public IActionResult Details(string id) { Package package = this.packageService.GetPackage(id); if (package == null) { return(this.BadRequest("Inavlid package id")); } CreatePackageViewModel viewModel = new CreatePackageViewModel() { DeliveryDate = package.DeliveryDate, Description = package.Description, Status = package.Status, ShippingAddress = package.ShippingAddress, Recepient = package.Recipient.UserName, Weight = package.Weight }; return(this.View(viewModel)); }
public IActionResult Manage(CreatePackageViewModel vm) { if (ModelState.IsValid) { //Mapping Package pac = new Package { PackageName = vm.PackageName, Details = vm.Details, Location = vm.Location, Price = vm.Price, Availability = vm.Availability }; //Save the Package to DB _repoPackage.Create(pac); //Redirect to Packages return(RedirectToAction("Packages")); } return(View(vm)); }
public IHttpResponse Create() { if (!this.User.IsLoggedIn) { return(this.Redirect("/users/login")); } if (this.User.Role != "Admin") { return(this.Redirect("/home/index")); } var model = new CreatePackageViewModel { Recipients = this.Db.Users.Select(u => new RecipientSmallViewModel { Name = u.Username }).ToList() }; return(this.View("Packages/Create", model)); }
public async Task <IActionResult> Create() { ApplicationUser currentUser = await _userManagerService.FindByNameAsync(User.Identity.Name); Provider currentProvider = _providerRepo.GetSingle(p => p.UserId == currentUser.Id); //Look up images on the server IEnumerable <string> imagePaths = new List <string>(); List <string> imageNames = new List <string>(); List <string> imageCorrectPaths = new List <string>(); string folderPath = _hostingEnv.WebRootPath + $@"\images\" + currentProvider.UserId; if (Directory.Exists(folderPath)) { imagePaths = Directory.GetFiles(folderPath); foreach (var item in imagePaths) { int endPos = item.LastIndexOf("\\"); string newString = item.Substring(endPos); imageCorrectPaths.Add($@"\images\" + currentProvider.UserId + newString); } } CreatePackageViewModel vm = new CreatePackageViewModel { ProviderId = currentProvider.ProviderId, IsActive = true, ImageNames = imageCorrectPaths //imageNames }; return(View(vm)); }
public async Task <ActionResult> Edit(CreatePackageViewModel data) { if (ViewBag.StudioID != data.studioid) { return(RedirectToAction("packagehome")); } if (!db.UserStudios.ToList().Any(x => x.userid == UserAuthentication.Identity().id&& x.studioid == data.studioid)) { return(RedirectToAction("Error500", "Home", new { errormsg = "You picked the wrong studio Fool!" })); } if (ModelState.IsValid) { try { if (data.price < data.depoprice || data.price <= 0 || data.depoprice < 0) { TempData["error"] = "Invalid price setting"; data.images = db.Packages.Find(data.id).PackageImages.ToList(); return(View("editpackage", data)); } var edit = db.Packages.First(x => x.id == data.id); edit.depositprice = data.depoprice; edit.details = string.IsNullOrWhiteSpace(data.details) ? null : data.details; edit.name = data.name; edit.price = data.price; edit.studioid = data.studioid; var img = db.PackageImages.Where(x => x.PackageID == data.id); if (!string.IsNullOrWhiteSpace(data.ImgName)) { if (img == null || img.FirstOrDefault(x => x.ImageName.ToLower() == data.ImgName.ToLower()) == null) { AzureBlob BlobManagerObj = new AzureBlob(2); foreach (var item in img) { BlobManagerObj.DeleteBlob(data.studioid.ToString(), String.Format("https://storagephotog2.blob.core.windows.net/studio-data/{0}/{1}", item.Package.studioid, item.ImageName)); } db.PackageImages.RemoveRange(img); PackageImage package = new PackageImage { ImageName = data.ImgName }; edit.PackageImages.Add(package); } } else { AzureBlob BlobManagerObj = new AzureBlob(2); foreach (var item in img) { BlobManagerObj.DeleteBlob(data.studioid.ToString(), String.Format("https://storagephotog2.blob.core.windows.net/studio-data/{0}/{1}", item.Package.studioid, item.ImageName)); } db.PackageImages.RemoveRange(img); } db.SaveChanges(); await UpdateFirebaseOrder(edit); return(RedirectToAction("PackageHome")); } catch (Exception e) { return(RedirectToAction("Error500", "Home", new { errormsg = e.Message })); } } return(View("editpackage", data)); }