public async Task <IActionResult> Response(object result, IEnumerable <Notification> notifications)
 {
     if (!notifications.Any())
     {
         try
         {
             _uow.Commit();
             return(Ok(new
             {
                 sucess = true,
                 data = result
             }));
         }
         catch
         {
             _uow.Rollback();
             return(BadRequest(new
             {
                 sucess = false,
                 errors = new [] { "Ocorreu uma falha no servidor." }
             }));
         }
     }
     else
     {
         _uow.Rollback();
         return(BadRequest(new
         {
             sucess = false,
             errors = notifications
         }));
     }
 }
示例#2
0
        public ActionResult Create([FromBody] Game game)
        {
            try
            {
                if (!game.IsValid())
                {
                    return(BadRequest("Verifique os campos"));
                }

                _uow.GameRepository.Add(game);
                _uow.Commit();

                return(Ok("Valores registrados com sucesso"));
            }
            catch
            {
                return(BadRequest("Houve um erro na requisição"));
            }
        }
示例#3
0
        public void BorrowBook(int bookId, int userId)
        {
            var book = _bookRepository.Get(x => x.Id == bookId).FirstOrDefault();

            if (book != null)
            {
                if (book.Quantity > 0)
                {
                    --book.Quantity;
                    _bookRepository.Update(book);

                    _bookBorrowRepository.Add(new BookBorrower()
                    {
                        BookId = bookId, UserId = userId
                    });

                    _uow.Commit();
                }
            }
        }
示例#4
0
        public void AddOrder(OrderRequest orderRequest)
        {
            //if customer ID is null then call off to create customer first
            int customerId = -1;

            if (!orderRequest.CustomerId.HasValue || orderRequest.CustomerId == -1)
            {
                customerId = _customerService.AddCustomer(new CustomerRequest {
                    Country = orderRequest.CustomerCountry, Name = orderRequest.CustomerName, DateOfBirth = orderRequest.DateOfBirth
                });
            }
            else
            {
                customerId = orderRequest.CustomerId.Value;
                Customer customer = _customerService.GetCustomer(customerId);
                orderRequest.CustomerName    = customer.Name;
                orderRequest.CustomerCountry = customer.Country;
            }
            //Change order request into order object and add to uow
            Order order = new Order {
                Amount = orderRequest.Amount, CustomerId = customerId
            };

            if (order.Amount <= 0)
            {
                throw new Exception("Order amount must be greater than zero");
            }

            if (orderRequest.CustomerCountry == "UK")
            {
                order.VAT = 0.2M;
            }
            else
            {
                order.VAT = 0;
            }
            _uow.Orders.Create(order);
            _uow.Commit();
        }
示例#5
0
        public int AddCustomer(CustomerRequest customerRequest)
        {
            if (String.IsNullOrEmpty(customerRequest.Country))
            {
                throw new Exception("Customer country cannot be empty");
            }
            if (String.IsNullOrEmpty(customerRequest.Name))
            {
                throw new Exception("Customer name cannot be empty");
            }
            if (customerRequest.DateOfBirth == null || customerRequest.DateOfBirth == DateTime.MinValue)
            {
                throw new Exception("Date Of Birth cannot be empty");
            }
            Customer customer = new Customer {
                Name = customerRequest.Name, Country = customerRequest.Country, DateOfBirth = customerRequest.DateOfBirth
            };
            var dbCustomerId = _uow.Customers.Create(customer);

            _uow.Commit();
            return(dbCustomerId);
        }
示例#6
0
 public async Task <IActionResult> ApiResponse(
     object result,
     IEnumerable <Notification> notifications)
 {
     //return await new Task<IActionResult>(() =>
     //{
     if (!notifications.Any())
     {
         try
         {
             _uow.Commit();
             return(Ok(new
             {
                 success = true,
                 data = result
             }));
         }
         catch (Exception e)
         {
             //Log do erro (Elmah)
             return(BadRequest(new
             {
                 success = false,
                 errors = new[] { "Ocorreu uma falha interna no servidor." },
                 exception = e.Message
             }));
         }
     }
     else
     {
         return(BadRequest(new
         {
             success = false,
             errors = notifications
         }));
     }
     //});
 }
示例#7
0
 public void Commit()
 {
     _uow.Commit();
 }
示例#8
0
        public bool CreateOrUpdateTeam(TeamDTO team, string UserId)
        {
            try
            {
                if (team.Id > 0)
                {
                    var checkAvailableTeam    = uow.TeamRepository.Get(x => x.Id == team.Id && !x.IsRemove).FirstOrDefault();
                    var checkAvailabilityName = uow.TeamRepository.Get(x => x.TeamName == team.TeamName && !x.IsRemove).FirstOrDefault();

                    if (checkAvailabilityName != null && checkAvailableTeam != null && checkAvailabilityName.Id == team.Id)
                    {
                        var InsertTeam = new Team
                        {
                            Id           = team.Id,
                            TeamName     = team.TeamName,
                            Point        = checkAvailableTeam.Point,
                            CreateDate   = checkAvailableTeam.CreateDate,
                            CreatedBy    = checkAvailableTeam.CreatedBy,
                            IsRemove     = false,
                            ModifiedBy   = UserId,
                            ModifiedDate = DateTime.Now,
                            TeamMatches  = checkAvailableTeam.TeamMatches,
                            TeamMembers  = checkAvailableTeam.TeamMembers
                        };

                        uow.TeamRepository.Update(InsertTeam);
                        uow.Commit();
                        return(true);
                    }
                    else if (checkAvailabilityName == null && checkAvailableTeam != null)
                    {
                        var InsertTeam = new Team
                        {
                            Id           = team.Id,
                            TeamName     = team.TeamName,
                            Point        = checkAvailableTeam.Point,
                            CreateDate   = checkAvailableTeam.CreateDate,
                            CreatedBy    = checkAvailableTeam.CreatedBy,
                            IsRemove     = false,
                            ModifiedBy   = UserId,
                            ModifiedDate = DateTime.Now,
                            TeamMatches  = checkAvailableTeam.TeamMatches,
                            TeamMembers  = checkAvailableTeam.TeamMembers
                        };

                        uow.TeamRepository.Update(InsertTeam);
                        uow.Commit();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                else
                {
                    var InsertTeam = new Team
                    {
                        TeamName     = team.TeamName,
                        Point        = team.Point,
                        CreateDate   = DateTime.Now,
                        CreatedBy    = UserId,
                        IsRemove     = false,
                        ModifiedBy   = UserId,
                        ModifiedDate = DateTime.Now,
                        TeamMatches  = null,
                        TeamMembers  = null
                    };

                    uow.TeamRepository.Insert(InsertTeam);
                    uow.Commit();
                    return(true);
                }
            }
            catch (Exception er)
            {
                var message = er.Message;
                return(false);
            }
        }
 public void CreateDeveloper(Developer developer)
 {
     UoW.DeveloperRepo.Save(developer);
     UoW.Commit();
 }