Ejemplo n.º 1
0
 public ActionResult <ObjectResult> RemoveAddress([FromBody] Model.Profile.Client.Entity.B2C.Client client)
 {
     try
     {
         ClientService clientService = new ClientService(Startup.BeePlaceDataBaseConnectionString);
         clientService.DeleteAddress(client);
         return(StatusCode((int)HttpStatusCode.OK, client));
     }
     catch (Exception e)
     {
         return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
     }
 }
Ejemplo n.º 2
0
        public void InsertClient(Model.Profile.Client.Entity.B2C.Client client)
        {
            try
            {
                client.Password = CryptHelper.Encrypt(client.Password);
                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);

                standartPersistence.Insert <Model.Profile.Client.Entity.B2C.Client>(client);
            }
            catch (SqlException e)
            {
                throw e;
            }
        }
Ejemplo n.º 3
0
 public ActionResult <ObjectResult> Insert([FromBody] Model.Profile.Client.Entity.B2C.Client client)
 {
     try
     {
         ClientService clientService = new ClientService(Startup.BeePlaceDataBaseConnectionString);
         client.DateCreated = DateTime.Now;
         client.DateUpdated = DateTime.Now;
         clientService.InsertClient(client);
         return(StatusCode((int)HttpStatusCode.OK, client));
     }
     catch (Exception e)
     {
         return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public List <OrderEstimate> ListOrderEstimate(Model.Profile.Client.Entity.B2C.Client client)
        {
            try
            {
                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);

                List <OrderEstimate> estimates = new List <OrderEstimate>();

                estimates = standartPersistence.GetEntities <OrderEstimate>(
                    CommandType.Text,
                    "SELECT * FROM OrderEstimate WHERE IdClient = @IdClient",
                    new { IdClient = client.Id }).ToList();

                foreach (var estimate in estimates)
                {
                    estimate.Company = new Company();
                    estimate.Company = standartPersistence.GetEntities <Company>(
                        CommandType.Text,
                        "SELECT * FROM Company WHERE Id = @IdCompany",
                        new { IdCompany = estimate.IdCompany }).SingleOrDefault();

                    estimate.OrderEstimateItems = new List <OrderEstimateItem>();
                    estimate.OrderEstimateItems = standartPersistence.GetEntities <OrderEstimateItem>(
                        CommandType.Text,
                        "SELECT * FROM OrderEstimateItem WHERE IdOrderEstimate = @IdOrderEstimate",
                        new { IdOrderEstimate = estimate.Id }).ToList();

                    estimate.Client = new Model.Profile.Client.Entity.B2C.Client();
                    estimate.Client = standartPersistence.GetEntities <Model.Profile.Client.Entity.B2C.Client>(
                        CommandType.Text,
                        "SELECT * FROM Client WHERE Id = @IdClient",
                        new { IdClient = estimate.IdClient }).SingleOrDefault();

                    estimate.Client.Address = new Address();
                    estimate.Client.Address = standartPersistence.GetEntities <Address>(
                        CommandType.Text,
                        "SELECT * FROM Address WHERE Id = @IdAddress",
                        new { estimate.IdAddress }).SingleOrDefault();
                }

                return(estimates);
            }
            catch (SqlException e)
            {
                throw e;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public List <Order> ListOrders(Model.Profile.Client.Entity.B2C.Client client)
        {
            try
            {
                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);

                List <Order> orders = new List <Order>();

                orders = standartPersistence.GetEntities <Order>(
                    CommandType.Text,
                    "SELECT * FROM Order WHERE IdClient = @IdClient",
                    new { IdClient = client.Id }).ToList();

                foreach (var order in orders)
                {
                    order.Company = new Company();
                    order.Company = standartPersistence.GetEntities <Company>(
                        CommandType.Text,
                        "SELECT * FROM Company WHERE Id = @IdCompany",
                        new { IdCompany = order.IdCompany }).SingleOrDefault();

                    order.OrderItems = new List <OrderItem>();
                    order.OrderItems = standartPersistence.GetEntities <OrderItem>(
                        CommandType.Text,
                        "SELECT * FROM OrderItem WHERE IdOrder = @IdOrder",
                        new { IdOrder = order.Id }).ToList();

                    order.Client = new Model.Profile.Client.Entity.B2C.Client();
                    order.Client = standartPersistence.GetEntities <Model.Profile.Client.Entity.B2C.Client>(
                        CommandType.Text,
                        "SELECT * FROM Client WHERE Id = @IdClient",
                        new { IdClient = order.IdClient }).SingleOrDefault();

                    order.Client.Address = new Address();
                    order.Client.Address = standartPersistence.GetEntities <Address>(
                        CommandType.Text,
                        "SELECT * FROM Address WHERE Id = @IdAddress",
                        new { order.IdAddress }).SingleOrDefault();
                }

                return(orders);
            }
            catch (SqlException e)
            {
                throw e;
            }
        }
Ejemplo n.º 6
0
 public ActionResult <ObjectResult> UpdateCredentials([FromBody] ClientCredentials credentials)
 {
     try
     {
         ClientService clientService = new ClientService(Startup.BeePlaceDataBaseConnectionString);
         var           client        = new Model.Profile.Client.Entity.B2C.Client();
         client.Email    = credentials.Email;
         client.Password = credentials.Password;
         clientService.UpdateClientCredentials(client);
         return(StatusCode((int)HttpStatusCode.OK, credentials));
     }
     catch (Exception e)
     {
         return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
     }
 }
Ejemplo n.º 7
0
        public void UpdateAddress(Model.Profile.Client.Entity.B2C.Client client)
        {
            try
            {
                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);

                if (client.Address != null)
                {
                    standartPersistence.Update <Address>(client.Address);
                }
            }
            catch (SqlException e)
            {
                throw e;
            }
        }
Ejemplo n.º 8
0
        public void UpdateClientCredentials(Model.Profile.Client.Entity.B2C.Client client)
        {
            try
            {
                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);

                client.Password = CryptHelper.Encrypt(client.Password);

                standartPersistence.Execute(CommandType.Text,
                                            "UPDATE Client SET Email = @Email, [Password] = @Password WHERE Email = @Email AND [Password] = @Password",
                                            new { client.Email, client.Password });
            }
            catch (SqlException e)
            {
                throw e;
            }
        }
Ejemplo n.º 9
0
        public Model.Profile.Client.Entity.B2C.Client LoginClient(Model.Profile.Client.Entity.B2C.Client client)
        {
            try
            {
                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);

                StringBuilder selectClient = new StringBuilder();
                string        pass         = CryptHelper.Encrypt(client.Password);
                selectClient.Append($"select * from Client where Email='{client.Email}' and Password='******'");
                client = standartPersistence.GetEntities <Model.Profile.Client.Entity.B2C.Client>(CommandType.Text, selectClient.ToString()).SingleOrDefault();

                StringBuilder selectAddress = new StringBuilder();
                selectAddress.Append(@" SELECT * FROM Address a
                     INNER JOIN ClientAddress ca ON a.Id = ca.IdAddress 
                     INNER JOIN Client c ON c.Id = ca.IdClient 
                     WHERE c.Id = @IdClient ");
                client.Addresses = new List <Address>();
                client.Addresses = standartPersistence.GetEntities <Address>(CommandType.Text, selectAddress.ToString(), new { IdClient = client.Id }).ToList();

                for (int i = 0; i < client.Addresses.Count; i++)
                {
                    client.Addresses[i].State = new State();
                    client.Addresses[i].State = standartPersistence.GetEntities <State>(CommandType.Text,
                                                                                        "SELECT IdEstate, UPPER(Name) AS Name, UF FROM State WHERE IdEstate = @IdEstate",
                                                                                        new { IdEstate = client.Addresses[i].IdEstate }).SingleOrDefault();

                    City city = new City();
                    city = standartPersistence.GetEntities <City>(CommandType.Text,
                                                                  "SELECT IdCity, Name, IdEstate FROM City WHERE IdCity = @IdCity",
                                                                  new { IdCity = client.Addresses[i].IdCity }).SingleOrDefault();

                    client.Addresses[i].State.Cities = new List <City>();
                    client.Addresses[i].State.Cities.Add(city);
                }
                return(client);
            }
            catch (TransactionException e)
            {
                throw e;
            }
        }
Ejemplo n.º 10
0
        public ActionResult <ObjectResult> Login([FromBody] Model.Profile.Client.Entity.B2C.Client client)
        {
            try
            {
                ClientService clientService = new ClientService(Startup.BeePlaceDataBaseConnectionString);
                client = clientService.LoginClient(client);

                if (client != null)
                {
                    return(StatusCode((int)HttpStatusCode.OK, client));
                }
                else
                {
                    return(StatusCode((int)HttpStatusCode.Unauthorized));
                }
            }
            catch (Exception e)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message));
            }
        }
Ejemplo n.º 11
0
        public void UpdateClient(Model.Profile.Client.Entity.B2C.Client client)
        {
            try
            {
                //   client.Password = CryptHelper.Encrypt(client.Password);
                //   StandartPersistence standartPersistence =
                //       new StandartPersistence(this.Connection);

                //client.DateCreated= standartPersistence.GetEntities<DateTime>(CommandType.Text, $@"select datecreated from Client  where id={client.Id}").FirstOrDefault();

                //   standartPersistence.Update(client);
                //   transactionScope.Complete();

                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);

                standartPersistence.Execute(CommandType.Text,
                                            "UPDATE Client SET FirstName = @FirstName, PhoneCodeArea = @PhoneCodeArea, Phone = @Phone, Confirmed = @Confirmed, AcceptedTerms = @AcceptedTerms, Status = @Status, Email = @Email, active = @active, DateUpdated = @DateUpdated, LastName = @LastName WHERE Id = @Id",

                                            new
                {
                    client.FirstName,
                    client.PhoneCodeArea,
                    client.Phone,
                    client.Confirmed,
                    client.AcceptedTerms,
                    client.Status,
                    client.Email,
                    client.Active,
                    client.DateUpdated,
                    client.LastName,
                    client.Id
                });
            }
            catch (SqlException e)
            {
                throw e;
            }
        }
Ejemplo n.º 12
0
        public List <CardData> ListCardDatas(Model.Profile.Client.Entity.B2C.Client client)
        {
            try
            {
                StandartPersistence standartPersistence =
                    new StandartPersistence(this.Connection);

                var cardDatas = standartPersistence.GetEntities <CardData>(CommandType.Text,
                                                                           "SELECT * FROM CardData WHERE IdCardOwner = @IdCardOwner AND IdCardOwnerType = @IdCardOwnerType ",
                                                                           new
                {
                    IdCardOwner     = client.Id,
                    IdCardOwnerType = (int)PaymentEnums.CardOwnerType.Client
                }).ToList();

                return(cardDatas);
            }
            catch (SqlException e)
            {
                throw e;
            }
        }
Ejemplo n.º 13
0
        public void InsertAddress(Model.Profile.Client.Entity.B2C.Client client)
        {
            using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
            {
                try
                {
                    StandartPersistence standartPersistence =
                        new StandartPersistence(this.Connection);

                    if (client.Address != null && client.Id > 0)
                    {
                        client.Address.DateCreated = DateTime.Now;
                        client.Address.DateUpdated = DateTime.Now;
                        standartPersistence.Insert <Address>(client.Address);

                        standartPersistence.Execute(CommandType.Text,
                                                    "INSERT INTO ClientAddress Values ( @IdAddress, @IdClient, @Main)",

                                                    new
                        {
                            IdClient  = client.Id,
                            IdAddress = client.Address.Id,
                            Main      = client.Address.Main
                        });
                    }

                    transactionScope.Complete();
                }
                catch (SqlException e)
                {
                    throw e;
                }
                catch (TransactionException e)
                {
                    throw e;
                }
            }
        }
Ejemplo n.º 14
0
        public void DeleteAddress(Model.Profile.Client.Entity.B2C.Client client)
        {
            StandartPersistence standartPersistence =
                new StandartPersistence(this.Connection);

            if (client.Addresses != null && client.Addresses.Count > 0)
            {
                for (int i = 0; i < client.Addresses.Count; i++)
                {
                    using (var transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew))
                    {
                        try
                        {
                            standartPersistence.Execute(CommandType.Text,
                                                        "DELETE FROM ClientAddress WHERE IdClient = @IdClient AND IdAddress = @IdAddress",
                                                        new
                            {
                                IdClient  = client.Id,
                                IdAddress = client.Addresses[i].Id
                            });

                            standartPersistence.Delete <Address>(client.Addresses[i]);

                            transactionScope.Complete();
                        }
                        catch (SqlException e)
                        {
                            throw e;
                        }
                        catch (TransactionException e)
                        {
                            throw e;
                        }
                    }
                }
            }
        }