Ejemplo n.º 1
0
        public async Task <IActionResult> PutSpeciality(int id, Speciality speciality)
        {
            if (id != speciality.Id)
            {
                return(BadRequest());
            }

            _context.Entry(speciality).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SpecialityExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <Department> > PostDepartment(PostDepartment postDepartment)
        {
            if (postDepartment == null)
            {
                return(NotFound(new ExceptionInfo
                {
                    Message = DepartmentErrorsMessages.DepartmentNotFound,
                    Description = "Отдел не найден по укзанному id"
                }));
            }

            var newDepartment = new Department {
                Name = postDepartment.Name
            };

            _context.Departments.Add(newDepartment);
            await _context.SaveChangesAsync();

            return(Ok(newDepartment));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PostBadge(RequestBadgePost requestBadgePost)
        {
            _context.BadgesWorkers.Add(new BadgesWorker {
                WorkerId = requestBadgePost.WorkerId,
                BadgeId  = requestBadgePost.BadgeId
            });

            await _context.SaveChangesAsync();

            return(Ok());
        }
        public async Task <ActionResult <ResponseProductList> > AddProduct([FromBody] CreateProduct createProduct)
        {
            var email       = User.Identity.Name;
            var currentUser = await _context.Workers.SingleAsync(x => x.Email == email);

            var file = await _context.Files.SingleOrDefaultAsync(x => x.Id == createProduct.FileId);

            if (file == null)
            {
                return(NotFound(new ExceptionInfo
                {
                    Message = ProductErrorsMessages.FileNotFound,
                    Description = "Не найден файл"
                }));
            }

            var fileUrl = Constans.ApiUrl + Constans.FileDownloadPart + file.Name;

            var tempProduct = new Product
            {
                Name        = createProduct.Name,
                Descriptiom = createProduct.Description,
                Price       = createProduct.Price,
                ImageUrl    = fileUrl
            };

            _context.Products.Add(tempProduct);
            await _context.SaveChangesAsync();

            var addedProduct = await _context.Products
                               .Include(x => x.FavoriteProductsWorkers)
                               .SingleAsync(x => x.Id == tempProduct.Id);

            var isFavorite = addedProduct.FavoriteProductsWorkers.Any(y => y.WorkerId == currentUser.Id && y.FavoriteProductId == addedProduct.Id);

            return(Ok(ResponseProductList.FromApiProduct(tempProduct, image: file, isFavorite: isFavorite, isCanBuy: currentUser.Balance >= tempProduct.Price)));
        }