示例#1
0
        public async Task <IActionResult> UpdateType(int id, BakeryType bakeryType)
        {
            if (id != bakeryType.Id)
            {
                return(BadRequest());
            }

            var typemodify = await _context.BakeryType.FindAsync(id);

            if (typemodify == null)
            {
                return(NotFound());
            }

            try
            {
                //await _repository.Update(bakery);
                _context.Entry(await _context.BakeryType.FirstOrDefaultAsync(x => x.Id == id)).CurrentValues.SetValues(bakeryType);
                await _context.SaveChangesAsync();
            }
            catch
            {
                return(NotFound());
            }

            return(NoContent());
        }
        public async Task <IActionResult> Edit(int id, BakeryType edittype)
        {
            if (ModelState.IsValid)
            {
                var type = await _service.GetType(id);

                if (type == null)
                {
                    return(NotFound());
                }

                var isAuthorize = await _authorizationService.AuthorizeAsync(User, type, ProductOperations.Update);

                if (!isAuthorize.Succeeded)
                {
                    return(Forbid());
                }

                await _service.UpdateType(id, edittype);

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
示例#3
0
        public async Task <ActionResult <Bakery> > CreateType(BakeryType bakeryType)
        {
            _context.BakeryType.Add(bakeryType);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
        public async Task <IActionResult> Create(BakeryType bakeryType)
        {
            if (ModelState.IsValid)
            {
                bakeryType.Status = true;
                //var isAuthorize = await _authorizationService.AuthorizeAsync(User, bakeryType, ProductOperations.Create);
                //if (!isAuthorize.Succeeded)
                //{
                //    return Forbid();
                //}

                await _service.CreateType(bakeryType);

                return(RedirectToAction(nameof(Index)));
            }

            return(View());
        }
示例#5
0
        public Bakery CreateBakery(BakeryType type, DateTime baked)
        {
            switch (type)
            {
            case BakeryType.Bagette:
                return(new Bagette(baked));

            case BakeryType.Crendel:
                return(new Crendel(baked));

            case BakeryType.Crousant:
                return(new Crousant(baked));

            case BakeryType.Smetannik:
                return(new Smetannik(baked));

            default:
                return(new Bagette(baked));
            }
        }
示例#6
0
        public async Task UpdateType(int id, BakeryType bakeryType)
        {
            var uri = _baseUrl + $"/updatetype/{id}";

            await _httpClient.PutAsync(uri, bakeryType);
        }
示例#7
0
        public async Task CreateType(BakeryType bakeryType)
        {
            var uri = _baseUrl + "/createtype";

            await _httpClient.PostAsync(uri, bakeryType);
        }