Пример #1
0
        public async Task <ActionResult> Create(DeliveryDriverCreate note)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.RestaurantId = await GetDeliveryDriversAsync();

                ViewBag.OrderId = await GetOrderAsync();

                return(View(note));
            }

            var service = CreateDeliveryDriverService();

            if (await service.CreateDeliveryDriverAsync(note))
            {
                TempData["SaveResult"] = " DeliveryDriver was created.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "DeliveryDriver could not be created.");
            ViewBag.RestaurantId = await GetDeliveryDriversAsync();

            ViewBag.OrderId = await GetOrderAsync();

            return(View(note));
        }
        public bool CreateDeliveryDriver(DeliveryDriverCreate model)
        {
            var entity =
                new DeliveryDriver()
            {
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Email       = model.Email,
                Username    = model.Username,
                PhoneNumber = model.PhoneNumber,
                IsActive    = model.IsActive,
                Latitude    = model.Latitude,
                Longitude   = model.Longitude
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.DeliveryDrivers.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public async Task <bool> CreateDeliveryDriverAsync(DeliveryDriverCreate model)
        {
            var entity =
                new DeliveryDriver()
            {
                // OwnerID = _userId,
                FirstName   = model.FirstName,
                LastName    = model.LastName,
                Email       = model.Email,
                Username    = model.Username,
                PhoneNumber = model.PhoneNumber,
                IsActive    = model.IsActive,
                Latitude    = model.Latitude,
                Longitude   = model.Longitude
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.DeliveryDrivers.Add(entity);
                return(await ctx.SaveChangesAsync() == 1);
            }
        }