public void Execute(int search, ExtraAddonRequestDTO request)
        {
            var extra = AiContext.ExtraAddons
                        .Find(search);

            if (extra == null || extra.IsDeleted == 1)
            {
                throw new EntityNotFoundException("Extra Add-on");
            }
            var existingName = AiContext.ExtraAddons
                               .Where(x => x.Name == request.Name)
                               .Where(x => x.Id != extra.Id)
                               .Where(x => x.IsDeleted == 0)
                               .FirstOrDefault();

            if (existingName != null)
            {
                throw new EntityExistsException("Extra Add-on");
            }
            var extraUpdate = new ExtraAddon();

            extra.Name       = request.Name;
            extra.Price      = request.Price;
            extra.ModifiedAt = DateTime.Now;
            AiContext.SaveChanges();
        }
Exemplo n.º 2
0
        public ExtraAddonResponseDTO Execute(ExtraAddonRequestDTO request)
        {
            var extra         = new ExtraAddon();
            var existingExtra = AiContext.ExtraAddons.Where(x => x.Name == request.Name).Where(x => x.IsDeleted == 0).FirstOrDefault();

            if (existingExtra != null)
            {
                throw new EntityExistsException("Extra add-on");
            }
            extra.Name  = request.Name;
            extra.Price = request.Price;
            AiContext.ExtraAddons.Add(extra);
            AiContext.SaveChanges();
            return(new ExtraAddonResponseDTO
            {
                Id = extra.Id,
                Name = extra.Name,
                Price = extra.Price
            });
        }