コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,FoodType")] TypeFoodEntity typeFoodEntity)
        {
            if (id != typeFoodEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(typeFoodEntity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TypeFoodEntityExists(typeFoodEntity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(typeFoodEntity));
        }
コード例 #2
0
 public TypeFoodResponse ToTypeFoodResponse(TypeFoodEntity typeFoodEntity)
 {
     return(new TypeFoodResponse
     {
         Id = typeFoodEntity.Id,
         FoodTypeName = typeFoodEntity.FoodTypeName
     });
 }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("Id,FoodType")] TypeFoodEntity typeFoodEntity)
        {
            if (ModelState.IsValid)
            {
                _context.Add(typeFoodEntity);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(typeFoodEntity));
        }
コード例 #4
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            TypeFoodEntity typeFoodEntity = await _context.TypeFoods
                                            .Include(t => t.Foods)
                                            .FirstOrDefaultAsync(m => m.Id == id);


            _context.TypeFoods.Remove(typeFoodEntity);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
コード例 #5
0
        // GET: TypeFoods/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TypeFoodEntity typeFoodEntity = await _context.TypeFoods.FindAsync(id);

            if (typeFoodEntity == null)
            {
                return(NotFound());
            }
            return(View(typeFoodEntity));
        }
コード例 #6
0
        // GET: TypeFoods/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TypeFoodEntity typeFoodEntity = await _context.TypeFoods
                                            .FirstOrDefaultAsync(m => m.Id == id);

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

            return(View(typeFoodEntity));
        }
コード例 #7
0
        public async Task <IActionResult> PostFood([FromBody] FoodRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new Response
                {
                    IsSuccess = false,
                    Message = "Bad request",
                    Result = ModelState
                }));
            }

            EstablishmentLocationEntity establishmentLocationEntity = await _context
                                                                      .EstablishmentLocations
                                                                      .FirstOrDefaultAsync(el => el.Id == request.EstablishmentLocationId);

            FoodEntity foodEntity = await _context.Foods.FirstOrDefaultAsync(f => f.FoodName == request.FoodName);

            TypeFoodEntity typeFoodEntity = await _context.TypeFoods.FirstOrDefaultAsync(f => f.Id == request.TypeFoodsId);

            UserEntity userEntity = await _userHelper.GetUserAsync(request.UserId);

            if (userEntity == null)
            {
                return(BadRequest("User doesn't exists."));
            }

            if (foodEntity != null)
            {
                if (establishmentLocationEntity.Id == foodEntity.EstablishmentLocations.Id)
                {
                    return(BadRequest(new Response
                    {
                        IsSuccess = false,
                        Message = "This food exist in this place"
                    }));
                }
            }

            string picturePath = string.Empty;

            if (request.PictureFoodArray != null && request.PictureFoodArray.Length > 0)
            {
                picturePath = await _blobHelper.UploadBlobAsync(request.PictureFoodArray, "foods");
            }

            FoodEntity food = new FoodEntity
            {
                FoodName                = request.FoodName,
                PicturePathFood         = picturePath,
                Qualification           = request.Qualification,
                Remarks                 = request.Remarks,
                TypeFoods               = typeFoodEntity,
                EstablishmentLocationId = establishmentLocationEntity.Id.ToString(),
                EstablishmentLocations  = establishmentLocationEntity,
                User = userEntity
            };

            _context.Foods.Add(food);
            await _context.SaveChangesAsync();

            return(Ok(_converterHelper.ToFoodResponse(food)));
        }