Ejemplo n.º 1
0
        public static async Task <int> Handler(this ShopCreate command, PostgresContext db)
        {
            var createTask = await db.Shops.AddAsync(new Shop(command.Title));

            await db.SaveChangesAsync();

            return(createTask.Entity.Id);
        }
Ejemplo n.º 2
0
        public bool CreateShop(ShopCreate model)
        {
            var entity = new Shop()
            {
                ShopName = model.ShopName,
                ShopURL  = model.ShopUrl
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Shops.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(ShopCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var service = new ShopService();

            if (service.CreateShop(model))
            {
                TempData["SaveResult"] = "Shop added.";
                return(RedirectToAction("Create", "Artist"));
            }
            ModelState.AddModelError("", "Shop could not be added.");
            return(View(model));
        }
Ejemplo n.º 4
0
        public IHttpActionResult Post([FromBody] ShopCreate shop
                                      )
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateShopService();

            if (!service.CreateShop(shop))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Ejemplo n.º 5
0
        public bool CreateShop(ShopCreate model)
        {
            var entity =
                new Shop()
            {
                OwnerId = _userId,
                //   MenuItemId=model.MenuItemId,
                Name     = model.Name,
                Location = model.Location,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Shops.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 6
0
        public int CreateShop(ShopCreate model)
        {
            byte[] bytes = null;
            if (model.File != null)
            {
                Stream       Fs = model.File.InputStream;
                BinaryReader Br = new BinaryReader(Fs);
                bytes = Br.ReadBytes((Int32)Fs.Length);
            }


            var service = new ShopHoursServices(0);
            var hoursId = service.CreateShopHours(new ShopHoursCreate());
            var entity  =
                new Shop()
            {
                OwnerID     = _userId,
                ShopName    = model.ShopName,
                OwnerName   = model.OwnerName,
                TypeShop    = model.TypeShop,
                Address     = model.Address,
                PhoneNumber = model.PhoneNumber,
                Email       = model.Email,
                Description = model.Description,
                HoursID     = hoursId,
                CreatedUtc  = DateTimeOffset.Now,
                FileContent = bytes
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Shops.Add(entity);

                if (ctx.SaveChanges() == 1)
                {
                    var hours = ctx.ShopHours.Single(e => e.HoursID == entity.HoursID);
                    hours.ShopID = entity.ShopID;
                    ctx.SaveChanges();
                    return(entity.ShopID);
                }
                else
                {
                    return(0);
                }
            }
        }
Ejemplo n.º 7
0
        //added from ElevenNote section 7.02
        public ActionResult Create(ShopCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var service = CreateShopService();
            var shopID  = service.CreateShop(model);

            if (shopID != 0)
            {
                TempData["SaveResult"] = "Your Shop was created.";
                return(RedirectToAction("Details", "Shop", new { ShopID = shopID }));
            }
            ;
            ModelState.AddModelError("", "Shop could not be created.");

            return(View(model));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Post([FromBody] ShopCreate command)
        {
            try
            {
                var shopCreateTask = await _db.Shops.AddAsync(new Shop()
                {
                    Title = command.Title
                });

                await _db.SaveChangesAsync();

                await command.Handler(_postgresContext);

                var result = shopCreateTask.Entity;

                return(Ok(new { id = result.Id, title = command.Title }));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }