Beispiel #1
0
        public IActionResult Update(ClientRequest req)
        {
            Response oResponse = new Response();

            try
            {
                using (Sales_DBContext db = new Sales_DBContext())
                {
                    Client oClient = db.Clients.Find(req.Id);
                    oClient.Name            = req.Name;
                    oClient.Ci              = req.Ci;
                    oClient.Number          = req.Number;
                    oClient.Address         = req.Address;
                    oClient.Email           = req.Email;
                    oClient.City            = req.City;
                    db.Entry(oClient).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                    db.SaveChanges();
                    oResponse.Success = 1;
                }
            }
            catch (Exception ex)
            {
                oResponse.Message = ex.Message;
            }

            return(Ok(oResponse));
        }
Beispiel #2
0
        public IActionResult Add(ClientRequest req)
        {
            Response oResponse = new Response();

            try
            {
                using (Sales_DBContext db = new Sales_DBContext())
                {
                    Client oClient = new Client();
                    oClient.Name    = req.Name;
                    oClient.Ci      = req.Ci;
                    oClient.Number  = req.Number;
                    oClient.Address = req.Address;
                    oClient.Email   = req.Email;
                    oClient.City    = req.City;
                    db.Clients.Add(oClient);
                    db.SaveChanges();
                    oResponse.Success = 1;
                }
            }
            catch (Exception ex)
            {
                oResponse.Message = ex.Message;
            }

            return(Ok(oResponse));
        }
        public IActionResult Add(SaleRequest req)
        {
            Response response = new Response();

            try
            {
                using (Sales_DBContext db = new Sales_DBContext())
                {
                    using (var transaction = db.Database.BeginTransaction())
                    {
                        try
                        {
                            Sale sale = new Sale();
                            sale.Total     = req.Concepts.Sum(d => d.Amount * d.UnitPrice);
                            sale.Date      = DateTime.Now;
                            sale.IdCliente = req.IdClient;
                            db.Add(sale);
                            db.SaveChanges();

                            foreach (var concept in req.Concepts)
                            {
                                Concept concept1 = new Concept
                                {
                                    Amount    = concept.Amount,
                                    IdProduct = concept.IdProduct,
                                    UnitPrice = concept.UnitPrice,
                                    Imports   = concept.Imports,
                                    IdSale    = sale.Id
                                };
                                db.Add(concept1);
                                db.SaveChanges();
                            }

                            transaction.Commit();
                            response.Success = 1;
                        }
                        catch (Exception ex)
                        {
                            transaction.Rollback();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return(Ok(response));
        }
Beispiel #4
0
        public IActionResult Get()
        {
            Response oResponse = new Response();

            try
            {
                using (Sales_DBContext db = new Sales_DBContext())
                {
                    var list = db.Clients.OrderBy(d => d.Id).ToList();
                    oResponse.Data    = list;
                    oResponse.Success = 1;
                }
            }
            catch (Exception ex)
            {
                oResponse.Message = ex.Message;
            }

            return(Ok(oResponse));
        }
Beispiel #5
0
        public IActionResult Delete(int id)
        {
            Response oResponse = new Response();

            try
            {
                using (Sales_DBContext db = new Sales_DBContext())
                {
                    Client oClient = db.Clients.Find(id);
                    db.Remove(oClient);
                    db.SaveChanges();
                    oResponse.Success = 1;
                }
            }
            catch (Exception ex)
            {
                oResponse.Message = ex.Message;
            }

            return(Ok(oResponse));
        }
Beispiel #6
0
        public UserResponse Auth(AuthRequest req)
        {
            UserResponse userResponse = new UserResponse();

            using (var db = new Sales_DBContext())
            {
                string spassword = Encrypt.GetSHA256(req.Password);

                var user = db.Users.Where(d => d.Email == req.Email &&
                                          d.Password == spassword).FirstOrDefault();

                if (user == null)
                {
                    return(null);
                }

                userResponse.Email = user.Email;
                userResponse.Token = GetToken(user);
            }

            return(userResponse);
        }