Ejemplo n.º 1
0
        public List <Order> Search(string status, string date)
        {
            IQueryable <Order> result = _context.Orders;

            if (status != null)
            {
                result = result.Where(o => o.Status == status);
            }
            if (date != null)
            {
                result = result.Where(o => o.Date.Equals(StringToDateTime.Convert(date, "yyyy-MM-dd")));
            }

            return(result
                   .Include(o => o.MerchandiseList)
                   .ThenInclude(m => m.Book)
                   .Include(o => o.ExchangedMerchandise)
                   .ThenInclude(m => m.Book)
                   .Include(o => o.CreditCardList)
                   .Include(o => o.CouponAppliedList)
                   .Include(o => o.DeliveryAddress)
                   .Include(o => o.BillingAddress)
                   .AsNoTracking()
                   .ToList());
        }
Ejemplo n.º 2
0
        public GenericCommandResult Validate()
        {
            var result  = true;
            var message = "";

            if (!TextValidator.Validity(CreditCardCompany))
            {
                result   = false;
                message += "CreditCardCompany is required\n";
            }
            if (!TextValidator.Validity(CardNumber, @"\d{16}", @"\D"))
            {
                result   = false;
                message += "CardNumber is required\n";
            }
            if (!TextValidator.Validity(Validity, @"\d{1,2}\/\d{4}"))
            {
                if (StringToDateTime.Convert(Validity, "M/yyyy") < DateTime.Now)
                {
                    result   = false;
                    message += "Validity is invalid, allow MM/yyyy\n";
                }
            }
            if (!TextValidator.Validity(Label))
            {
                result   = false;
                message += "Label is required\n";
            }

            return(new GenericCommandResult(result, message));
        }
 public async Task <ActionResult <List <Order> > > Search(
     [FromQuery(Name = "searchtype")] string searchType,
     [FromQuery(Name = "initialDate")] string initialDate,
     [FromQuery(Name = "finalDate")] string finalDate,
     [FromQuery] string status,
     [FromQuery] string date,
     [FromServices] IOrderRepository repository
     )
 {
     if (searchType.Equals("chart-populate"))
     {
         return(Ok(repository.GetAllByPeriod(
                       StringToDateTime.Convert(initialDate, "yyyy-MM-dd"),
                       StringToDateTime.Convert(finalDate, "yyyy-MM-dd").AddHours(23.99)
                       )));
     }
     if (searchType.Equals("default"))
     {
         return(Ok(repository.Search(
                       status,
                       date
                       )));
     }
     return(BadRequest());
 }
Ejemplo n.º 4
0
        public List <Customer> Search(
            string name,
            string lastName,
            string gender,
            string cpf,
            string birthDate,
            string phone,
            string email,
            int?active
            )
        {
            IQueryable <Customer> result = _context.Customers;

            if (name != null)
            {
                result = result.Where(c => c.Name.Contains(name));
            }
            if (lastName != null)
            {
                result = result.Where(c => c.LastName.Contains(lastName));
            }
            if (gender != null)
            {
                result = result.Where(c => c.Gender.Equals(gender));
            }
            if (cpf != null)
            {
                result = result.Where(c => c.CPF.Equals(cpf));
            }
            if (birthDate != null)
            {
                result = result.Where(c => c.BirthDate.Equals(StringToDateTime.Convert(birthDate, "yyyy-MM-dd")));
            }
            if (phone != null)
            {
                result = result.Where(c => c.Phone.Contains(phone));
            }
            if (email != null)
            {
                result = result.Where(c => c.Email.Contains(email));
            }
            if (active != null)
            {
                result = result.Where(c => c.Active == active);
            }

            return(result
                   .Include(c => c.AddressList)
                   .Include(c => c.CreditCardList)
                   .AsNoTracking()
                   .ToList());
        }
        public GenericCommandResult Validate()
        {
            var result  = true;
            var message = "";

            if (!TextValidator.Validity(Name))
            {
                result   = false;
                message += "Name is required\n";
            }
            if (!TextValidator.Validity(LastName))
            {
                result   = false;
                message += "LastName is required\n";
            }
            if (!TextValidator.Validity(Gender, @"^[f|m|u]$"))
            {
                result   = false;
                message += "Gender is required, allow values f|m|u\n";
            }
            if (!TextValidator.Validity(CPF, @"(\d{11})|(\d{3}\.\d{3}\.\d{3}-\d{2})"))
            {
                result   = false;
                message += "CPF is required, allow \\d{11} or 000.000.000-00 \n";
            }
            if (!TextValidator.Validity(BirthDate, @"\d{4}-\d{2}-\d{2}"))
            {
                if (StringToDateTime.Convert(BirthDate, "yyyy-MM-dd") > DateTime.Now.AddYears(-4))
                {
                    result   = false;
                    message += "BirthDate is invalid, allow \n";
                }
            }
            if (!TextValidator.Validity(Phone, @"(\d{10,11})|(\(\d{2}\)\s\d{4,5}-\d{4})", @"\D"))
            {
                result   = false;
                message += "Phone is required, allow \\d{11} or (00) 90000-0000\n";
            }
            if (!TextValidator.Validity(Email, @".+@.{1,}\..{1,}"))
            {
                result   = false;
                message += "Email is required\n";
            }

            return(new GenericCommandResult(result, message));
        }
Ejemplo n.º 6
0
        public ICommandResult Handle(CreateCustomerCommand command)
        {
            var address = new Address(
                command.HomeType,
                command.PublicPlaceType,
                command.PublicPlaceName,
                command.HomeNumber,
                command.CEP,
                command.Neighborhood,
                command.City,
                command.State,
                command.Country,
                command.Complement,
                command.AddressLabel
                );

            var customer = new Customer(
                command.UserId,
                command.Name,
                command.LastName,
                command.Gender,
                command.CPF,
                StringToDateTime.Convert(command.BirthDate, "yyyy-MM-dd"),
                command.Phone,
                command.Email,
                command.Active,
                new List <Address> {
                address
            }
                );

            var strategy       = new CreateCustomerStrategy();
            var strategyResult = (GenericCommandResult)strategy.Execute(customer, _repository);

            if (!strategyResult.Success)
            {
                return(strategyResult);
            }

            _repository.CreateCustomer(customer);
            _repository.SaveChanges();
            return(new GenericCommandResult(true, "Sucesso no registro do cliente", customer));
        }
        public List <Coupon> Search(
            float value,
            string status,
            string type,
            string code,
            string date,
            int customerId
            )
        {
            IQueryable <Coupon> result = _context.Coupons;

            if (value != 0)
            {
                result = result.Where(c => c.Value == value);
            }
            if (status != null)
            {
                result = result.Where(c => c.Status.Contains(status));
            }
            if (type != null)
            {
                result = result.Where(c => c.Type.Contains(type));
            }
            if (code != null)
            {
                result = result.Where(c => c.Code.Contains(code));
            }
            if (date != null)
            {
                result = result.Where(c => c.Date.Equals(StringToDateTime.Convert(date, "yyyy-MM-dd")));
            }
            if (customerId != 0)
            {
                result = result.Where(c => c.CustomerId == customerId);
            }

            return(result
                   .AsNoTracking()
                   .ToList());
        }
Ejemplo n.º 8
0
        public ICommandResult Handle(CreateCustomerCreditCardCommand command)
        {
            var customer = _repository.GetById(command.CustomerId);

            if (customer == null)
            {
                return(new GenericCommandResult(false, "Cliente não encontrado", null));
            }

            var creditCard = new CreditCard(
                command.CreditCardCompany,
                command.CardNumber,
                StringToDateTime.Convert(command.Validity, "M/yyyy"),
                command.Label
                );

            customer.CreditCardList.Add(creditCard);
            _repository.UpdateCustomerCreditCardList(customer);
            _repository.SaveChanges();

            return(new GenericCommandResult(true, "Cartão adicionado com sucesso", customer));
        }
        public Customer MergeEntity(Customer customer)
        {
            // foreach (var prop in this.GetType().GetProperties())
            // {
            //     var value = this.GetType().GetProperty(prop.Name).GetValue(this);
            //     if(value != null && prop.CanWrite)
            //     {
            //         prop.SetValue(customer, Convert.ChangeType(value, prop.PropertyType));
            //     }
            // }
            if (Name != null && !customer.Name.Equals(Name))
            {
                customer.Name = Name;
            }
            if (LastName != null && !customer.LastName.Equals(LastName))
            {
                customer.LastName = LastName;
            }
            if (Gender != null && !customer.Gender.Equals(Gender))
            {
                customer.Gender = Gender;
            }
            if (CPF != null && !customer.CPF.Equals(CPF))
            {
                customer.CPF = CPF;
            }
            if (BirthDate != null)
            {
                customer.BirthDate = StringToDateTime.Convert(BirthDate, "yyyy-MM-dd");
            }
            if (Phone != null && !customer.Phone.Equals(Phone))
            {
                customer.Phone = Phone;
            }

            Entity = customer;
            return(customer);
        }
Ejemplo n.º 10
0
        public GenericCommandResult Validate()
        {
            var result  = true;
            var message = "";

            if (!TextValidator.Validity(Name))
            {
                result   = false;
                message += "Name is required\n";
            }
            if (!TextValidator.Validity(LastName))
            {
                result   = false;
                message += "LastName is required\n";
            }
            if (!TextValidator.Validity(Gender, @"^[f|m|u]$"))
            {
                result   = false;
                message += "Gender is required, allow values f|m|u\n";
            }
            if (!TextValidator.Validity(CPF, @"(\d{11})|(\d{3}\.\d{3}\.\d{3}-\d{2})"))
            {
                result   = false;
                message += "CPF is required, allow \\d{11} or 000.000.000-00 \n";
            }
            if (!TextValidator.Validity(BirthDate, @"\d{4}-\d{2}-\d{2}"))
            {
                if (StringToDateTime.Convert(BirthDate, "yyyy-MM-dd") > DateTime.Now.AddYears(-4))
                {
                    result   = false;
                    message += "BirthDate is invalid, allow \n";
                }
            }
            if (!TextValidator.Validity(Phone, @"(\d{10,11})|(\(\d{2}\)\s\d{4,5}-\d{4})", @"\D"))
            {
                result   = false;
                message += "Phone is required, allow \\d{11} or (00) 90000-0000\n";
            }
            if (!TextValidator.Validity(Email, @".+@.{1,}\..{1,}"))
            {
                result   = false;
                message += "Email is required\n";
            }
            if (!TextValidator.Validity(Password, @"(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*\W).{8,}"))
            {
                result   = false;
                message += "Password is required, allow one uppercase letter, one lowercase letter and one special character, and have more than 8 characters\n";
            }
            if (!TextValidator.Validity(HomeType))
            {
                result   = false;
                message += "HomeType is required\n";
            }
            if (!TextValidator.Validity(PublicPlaceType))
            {
                result   = false;
                message += "PublicPlaceType is required\n";
            }
            if (!TextValidator.Validity(PublicPlaceName))
            {
                result   = false;
                message += "PublicPlaceName is required\n";
            }
            if (!TextValidator.Validity(HomeNumber, @"(?=.*\d).{1,}"))
            {
                result   = false;
                message += "HomeNumber is required\n";
            }
            if (!TextValidator.Validity(CEP, @"(\d{8})|(\d{5}-\d{3})", @"\D"))
            {
                result   = false;
                message += "CEP is required, allow \\d{8} or 00000-000 \n";
            }
            if (!TextValidator.Validity(Neighborhood))
            {
                result   = false;
                message += "Neighborhood is required\n";
            }
            if (!TextValidator.Validity(City))
            {
                result   = false;
                message += "City is required\n";
            }
            if (!TextValidator.Validity(State))
            {
                result   = false;
                message += "State is required\n";
            }
            if (!TextValidator.Validity(Country))
            {
                result   = false;
                message += "Country is required\n";
            }
            if (!TextValidator.Validity(AddressLabel))
            {
                result   = false;
                message += "AddressLabel is required\n";
            }

            return(new GenericCommandResult(result, message));
        }
        public dynamic Populate(
            [FromServices] IUserRepository repository,
            [FromServices] ICustomerRepository customerRepository,
            [FromServices] IProductRepository productRepository,
            [FromServices] IMerchandiseRepository merchandiseRepository,
            [FromServices] ICategoryRepository categoryRepository,
            [FromServices] IPriceGroupRepository priceGroupRepository
            )
        {
            if (customerRepository.GetAll().Count() > 0)
            {
                return(BadRequest());
            }

            var manager = new User {
                Email = "*****@*****.**", Password = "******", Role = "manager"
            };

            repository.CreateUser(manager);
            repository.SaveChanges();

            var address = new Address {
                HomeType        = "casa",
                PublicPlaceType = "rua",
                PublicPlaceName = "um",
                HomeNumber      = "11",
                CEP             = "08843660",
                Neighborhood    = "Jardim modelo",
                City            = "Cidade piloto",
                State           = "Acre",
                Country         = "Brasil",
                Complement      = "",
                AddressLabel    = "end principal"
            };

            var customer = new Customer {
                UserId      = manager.Id,
                Name        = "Kelvin",
                LastName    = "Jesus",
                Gender      = "m",
                CPF         = "01234567890",
                BirthDate   = StringToDateTime.Convert("18/05/1993"),
                Phone       = "1147224889",
                Email       = manager.Email,
                Active      = 1,
                AddressList = new List <Address> {
                    address
                },
            };

            var card = new CreditCard {
                CreditCardCompany = "visa",
                CardNumber        = "1234123412341234",
                Validity          = StringToDateTime.Convert("05/2025", "M/yyyy"),
                Label             = "meu visa principal"
            };

            customer.CreditCardList = new List <CreditCard> {
                card
            };

            customerRepository.CreateCustomer(customer);
            customerRepository.SaveChanges();

            var pG1 = new PriceGroup("Padrão", 1.2f);
            var pG2 = new PriceGroup("Estratégico", 0.75f);
            var pG3 = new PriceGroup("Especial", 1.4f);

            priceGroupRepository.CreateManyPriceGroup(new List <PriceGroup> {
                pG1, pG2, pG3
            });
            priceGroupRepository.SaveChanges();

            var cat1 = new Category("Aventura", "volumes com contos fantasiosos e fantásticos");
            var cat2 = new Category("Suspense", "volumes com histórias de misterio");
            var cat3 = new Category("Romance", "livros com historias de paixão e amor");
            var cat4 = new Category("Técnicos", "faciculos com aplicações práticas em diciplinas exatas");
            var cat5 = new Category("Infantis", "contos lúdicos pra crianças");
            var cat6 = new Category("Quadrinhos", "historias ilustradas de ficcção cientificas e ação para jovens");

            categoryRepository.CreateManyCategory(new List <Category> {
                cat1, cat2, cat3, cat5, cat6
            });
            categoryRepository.SaveChanges();

            return(Ok());
        }
Ejemplo n.º 12
0
        public ActionResult <Appointment> AddAppointment([FromBody] DTOAppointment dtoAppointment)
        {
            var claims = User.Claims;
            var userId = claims.FirstOrDefault(x => x.Type == "id")?.Value;

            if (userId != dtoAppointment.OwnerId.ToString())
            {
                return(Unauthorized());
            }

            using (var unit = _factory.GetUOF())
            {
                try
                {
                    var dbUser    = unit.Users.GetEager(dtoAppointment.OwnerId);
                    var startTime = StringToDateTime.Convert(dtoAppointment.StartTime);
                    var endTime   = StringToDateTime.Convert(dtoAppointment.EndTime);

                    // Create appointment
                    var appointment = new Appointment
                    {
                        Participants    = new List <CalendarAppointment>(),
                        StartTime       = startTime,
                        EndTime         = endTime,
                        Text            = dtoAppointment.Text,
                        Title           = dtoAppointment.Title,
                        MaxParticipants = dtoAppointment.MaxParticipants,
                        OwnerId         = dtoAppointment.OwnerId
                    };

                    //Check if there is a spot in the calendar
                    var occupiedTime = dbUser.Calendar.Appointments.Any(x => x.Appointment.StartTime <= appointment.StartTime &&
                                                                        x.Appointment.EndTime >= appointment.StartTime);

                    if (occupiedTime)
                    {
                        return(BadRequest(new { message = "Please pick a free spot in the calendar" }));
                    }

                    var calendarAppointment = new CalendarAppointment
                    {
                        Appointment = appointment,
                        Calendar    = dbUser.Calendar
                    };

                    dbUser.Calendar.Appointments.Add(calendarAppointment);
                    unit.Complete();

                    var res = new DTOAppointmentPrivate
                    {
                        Participants = new List <DTOSimpleUser>()
                    };
                    var simpleUser = new DTOSimpleUser();
                    Mapper.Map(dbUser, simpleUser);
                    res.Participants.Add(simpleUser);

                    Mapper.Map(appointment, res);

                    return(CreatedAtAction("GetAppointment", new { appointmentId = res.Id }, res));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }