Beispiel #1
0
        public IActionResult Create()
        {
            var model = new PackageCreateInputModel();

            model.Users = this.context.Users.Select(u => u.UserName).ToList();

            return(this.View(model));
        }
Beispiel #2
0
        public IActionResult Create()
        {
            var model = new PackageCreateInputModel();

            model.Recipients = this.accountService.AllUsers();

            return(this.View(model));
        }
Beispiel #3
0
        public IActionResult Create(PackageCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Packages/Create"));
            }

            this.packageService.Create(model.Description, model.Weight, model.ShippingAddress, model.RecipientName);
            return(this.Redirect("/Packages/Pending"));
        }
Beispiel #4
0
        public async Task <IActionResult> Create(PackageCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            await this.packageService.CreateAsync(model);

            return(Redirect("/"));
        }
Beispiel #5
0
        public IActionResult Create(PackageCreateInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Packages/Create"));
            }


            this.packageService.AddPackageToDb(inputModel.Description, inputModel.ShippingAddress, inputModel.Weight, inputModel.RecipientName);
            return(this.Redirect("/Home/Index"));
        }
        public IActionResult Create(PackageCreateInputModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewData["Users"] = packageService.GetAllRecipients();
                return(View(model));
            }

            packageService.Create(model);
            return(RedirectToAction("Index", "Home"));
        }
Beispiel #7
0
        public IActionResult Create()
        {
            var recipients = this.dbContext.Users
                             .Select(x => new RecipientDropDownModel {
                Id = x.Id, FullName = x.UserName
            }).ToList();
            var viewModel = new PackageCreateInputModel
            {
                Recipients = recipients
            };

            return(this.View(viewModel));
        }
        public void Create(PackageCreateInputModel model)
        {
            Package package = new Package()
            {
                Description     = model.Description,
                RecipientId     = model.RecipientId,
                Weight          = model.Weight,
                ShippingAddress = model.ShippingAddress
            };

            context.Packages.Add(package);
            context.SaveChanges();
        }
Beispiel #9
0
        public IHttpResponse Create()
        {
            var users = Db.Users.Select(u => new RecipientViewModel()
            {
                Id       = u.Id,
                Username = u.Username
            });

            var model = new PackageCreateInputModel()
            {
                Recipients = users.ToList()
            };

            return(this.View(model));
        }
Beispiel #10
0
        public IActionResult Create(PackageCreateInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                IEnumerable <string> models = this.usersService.GetAllUserNames();

                ViewData["Recipients"] = models;

                return(this.View(model));
            }

            this.packagesService.Create(model.Description, model.Weight, model.ShippingAddress, model.Recipient);

            return(this.Redirect("/"));
        }
Beispiel #11
0
        public async Task CreateAsync(PackageCreateInputModel model)
        {
            var package = new Package
            {
                Description           = model.Description,
                PackageStatus         = PackageStatus.Pending,
                RecipientId           = model.RecipientId,
                ShippingAddress       = model.ShippingAddress,
                Weight                = model.Weight,
                EstimatedDeliveryDate = DateTime.UtcNow.AddDays(new Random().Next(0, 11))
            };

            await this.DbContext.Packages.AddAsync(package);

            await this.DbContext.SaveChangesAsync();
        }
        public HttpResponse Create(PackageCreateInputModel input)
        {
            if (!this.IsUserLoggedIn())
            {
                return(this.Redirect("/Users/Login"));
            }

            if (input.Description?.Length < 5 || input.Description?.Length > 20 || string.IsNullOrWhiteSpace(input.Description))
            {
                return(this.Redirect("/Package/Create"));
            }

            this.packageService.CreatePackage(input.Description, input.Weight, input.ShippingAddress, input.RecipientName);

            return(this.Redirect("/Packages/Pending"));
        }
Beispiel #13
0
        public IHttpResponse Create(PackageCreateInputModel model)
        {
            var package = new Package()
            {
                Description          = model.Description,
                ShippingAddress      = model.ShippingAddress,
                Weight               = model.Weight,
                EstimateDeliveryDate = null,
                RecipientId          = model.RecipientId,
                Status               = Status.Pending
            };

            this.Db.Packages.Add(package);
            this.Db.SaveChanges();

            return(this.Redirect("/"));
        }
Beispiel #14
0
        public IActionResult Create(PackageCreateInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/Packages/Create"));
            }

            Package package = model.MapTo <Package>();
            string  userId  = usersService.GetUserIdByUsername(model.RecipientName);

            if (userId == null)
            {
                ModelState.Add("Recipient", "Recipient is invalid!");
                return(Redirect("/Packages/Create"));
            }
            package.RecipientId = userId;

            packagesService.CreatePackage(package);

            return(Redirect("/Packages/Pending"));
        }
Beispiel #15
0
        public IActionResult Create(PackageCreateInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.Redirect("/Packages/Create"));
            }

            User recipient = this.userService.GetUserByUsername(model.RecipientName);

            Package package = new Package
            {
                Description     = model.Description,
                Weight          = model.Weight,
                ShippingAddress = model.ShippingAddress,
                RecipientId     = recipient.Id
            };

            this.packageService.CreatePackage(package);

            return(this.Redirect("/Packages/Pending"));
        }
Beispiel #16
0
        public IActionResult Create(PackageCreateInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }
            var package = new Package
            {
                Description     = inputModel.Description,
                Weight          = inputModel.Weight,
                ShippingAddress = inputModel.ShippingAddress,
                Status          = this.dbContext.PackageStatuses.FirstOrDefault(x => x.Name == "Pending"),
                RecipientId     = inputModel.RecipientId
            };

            this.dbContext.Packages.Add(package);
            this.dbContext.SaveChanges();

            //TODO Redirect to details view
            return(this.Redirect("/Home/Index"));
        }
Beispiel #17
0
        public IHttpResponse Create(PackageCreateInputModel model)
        {
            var description     = model.Description;
            var weight          = model.Weight;
            var shippingAddress = model.ShippingAddress;
            var recipientName   = model.Recipient;

            var recipient = this.Context.Users
                            .FirstOrDefault(u => u.Username == recipientName);

            if (recipient == null)
            {
                return(this.BadRequestErrorWithView("Invalid recipient username."));
            }

            var package = new Package
            {
                Description           = description,
                ShippingAddress       = shippingAddress,
                Weight                = double.Parse(weight),
                Recipient             = recipient,
                Status                = PackageStatus.Pending,
                EstimatedDeliveryDate = null
            };

            this.Context.Packages.Add(package);

            try
            {
                this.Context.SaveChanges();
            }
            catch (System.Exception e)
            {
                return(this.BadRequestError(e.Message));
            }

            return(this.Redirect("/"));
        }
Beispiel #18
0
        public IActionResult Create(PackageCreateInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Packages/Create"));
            }

            var userId = this.context.Users.FirstOrDefault(u => u.UserName == inputModel.Recipient).Id;

            var package = new Package()
            {
                RecipientId           = userId,
                Description           = inputModel.Description,
                ShippingAddress       = inputModel.ShippingAddress,
                Status                = this.context.PackageStatuses.FirstOrDefault(s => s.Name == "Pending"),
                Weight                = inputModel.Weight,
                EstimatedDeliveryDate = DateTime.UtcNow.AddDays(20)
            };

            this.context.Packages.Add(package);
            this.context.SaveChanges();

            return(this.Redirect("/Packages/Pending"));
        }