public EResponseBase <Customer> Add(Customer customer)
        {
            customer.State     = true;
            customer.CreatedAt = DateTime.Now;
            EResponseBase <Customer> response = new EResponseBase <Customer>();

            try
            {
                using (var context = new DataContext())
                {
                    context.Customers.Add(customer);
                    context.SaveChanges();
                }
                response.Status  = true;
                response.Message = "Success";
                response.Object  = customer;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
                return(response);
            }
        }
예제 #2
0
        public EResponseBase <Product> Update(Product product)
        {
            EResponseBase <Product> response = new EResponseBase <Product>();

            try
            {
                using (var context = new DataContext())
                {
                    var newProduct = context.Products.Find(product.ProductID);
                    newProduct.Name        = product.Name;
                    newProduct.Stock       = product.Stock;
                    newProduct.UnitPrice   = product.UnitPrice;
                    newProduct.Description = product.Description;
                    context.SaveChanges();
                }
                response.Status  = true;
                response.Message = "Success";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
            }
            return(response);
        }
예제 #3
0
        public EResponseBase <User> Add(User model)
        {
            EResponseBase <User> response = new EResponseBase <User>();

            try
            {
                using (var context = new DataContext())
                {
                    model.CreateAt = DateTime.Now;
                    //model.State = true;
                    context.Users.Add(model);
                    context.SaveChanges();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                response.Object    = model;
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #4
0
        public EResponseBase <Customer> Update(Customer model)
        {
            EResponseBase <Customer> response = new EResponseBase <Customer>();

            try
            {
                using (var context = new DataContext())
                {
                    var item = context.Customers.Find(model.CustomerID);
                    item.Name      = model.Name;
                    item.LastName  = model.LastName;
                    item.Birthdate = model.Birthdate;
                    context.SaveChanges();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #5
0
        public EResponseBase <DataBill> Add(DataBill dataBill)
        {
            EResponseBase <DataBill> response = new EResponseBase <DataBill>();

            try
            {
                dataBill.Customer.State     = true;
                dataBill.Customer.CreatedAt = DateTime.Now;
                dataBill.Bill.CreatedAt     = DateTime.Now;
                dataBill.Bill.State         = true;
                dataBill.Bill.BillDetails   = dataBill.BillDetails;
                dataBill.Bill.Customer      = dataBill.Customer;
                using (var context = new DataContext())
                {
                    context.Bills.Add(dataBill.Bill);
                    context.SaveChanges();
                }
                response.Status  = true;
                response.Message = "Success";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
            }
            return(response);
        }
예제 #6
0
        public EResponseBase <User> Update(User model)
        {
            EResponseBase <User> response = new EResponseBase <User>();

            try
            {
                using (var context = new DataContext())
                {
                    var User = context.Users.Where(x => x.UserID == model.UserID).FirstOrDefault();
                    User.Name     = model.Name;
                    User.LastName = model.LastName;
                    //User.Email = model.Email;
                    //User.Birthdate = model.Birthdate;
                    context.SaveChanges();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #7
0
        public EResponseBase <SalesInvoce> Update(SalesInvoce model)
        {
            EResponseBase <SalesInvoce> response = new EResponseBase <SalesInvoce>();

            try
            {
                using (var context = new DataContext())
                {
                    var item = context.SalesInvoces.Where(x => x.SalesInvoceID == model.SalesInvoceID).FirstOrDefault();
                    item.Reason     = model.Reason;
                    item.SellerID   = model.SellerID;
                    item.CustomerID = model.CustomerID;
                    context.SaveChanges();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #8
0
        public EResponseBase <CustomBill> Get()
        {
            EResponseBase <CustomBill> response = new EResponseBase <CustomBill>();

            try
            {
                using (var context = new DataContext())
                {
                    response.List = context.Bills.Join(context.BillDetails, o => o.BillID, od => od.BillID,
                                                       (o, od) => new CustomBill
                    {
                        BillID   = o.BillID,
                        Customer = o.Customer.Name,
                        SalesMan = o.SalesMan.Name,
                        Code     = o.Code,
                        Quantity = od.Quantity,
                        Price    = od.Price,
                        IGV      = o.IGV,
                        Subtotal = (od.Quantity * od.Price),
                        SalesTax = o.IGV / 100 * od.Quantity * od.Price,
                        Total    = (od.Quantity * od.Price) + (o.IGV / 100 * od.Quantity * od.Price
                                                               )
                    }).ToList();
                }
                response.Status  = true;
                response.Message = "Success";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
            }
            return(response);
        }
예제 #9
0
        //public EResponseBase<User> Get(string ID)
        //{
        //    EResponseBase<User> response = new EResponseBase<User>();
        //    try
        //    {
        //        using (var context = new DataContext())
        //        {
        //            response.Object = context.Users.Where(x => x.UserID == ID && x.State == true).FirstOrDefault();
        //        }
        //        response.IsSuccess = true;
        //        response.Message = "Success";
        //        return response;
        //    }
        //    catch (Exception ex)
        //    {
        //        response.Message = ex.Message;
        //        response.IsSuccess = false;
        //        return response;
        //    }
        //}

        public EResponseBase <User> Login(string usuario, string password)
        {
            EResponseBase <User> response = new EResponseBase <User>();

            try
            {
                using (var context = new DataContext())
                {
                    response.Object = context.Users.Where(x => x.UserName == usuario && x.Password == password).FirstOrDefault();
                }

                if (response.Object == null)
                {
                    response.Message = "Usuario y Contraseña incorrecta!";
                    response.Code    = 201;
                }
                else
                {
                    response.Code    = 200;
                    response.Message = "Success";
                }
                response.IsSuccess = true;


                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #10
0
        public EResponseBase <SalesInvoce> Get(int ID)
        {
            EResponseBase <SalesInvoce> response = new EResponseBase <SalesInvoce>();

            try
            {
                using (var context = new DataContext())
                {
                    response.Object = context.SalesInvoces
                                      .Include("Customer")
                                      .Include("Seller")
                                      .Include("SalesInvoceDetails.Product")
                                      .Where(x => x.SalesInvoceID == ID && x.State == true).FirstOrDefault();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #11
0
        public EResponseBase <Customer> Update(Customer customer)
        {
            EResponseBase <Customer> response = new EResponseBase <Customer>();

            try
            {
                using (var context = new DataContext())
                {
                    var newCustomer = context.Customers.Find(customer.CustomerID);
                    newCustomer.Name     = customer.Name;
                    newCustomer.LastName = customer.LastName;
                    newCustomer.Phone    = customer.Phone;
                    newCustomer.Address  = customer.Address;
                    context.SaveChanges();
                }
                response.Status  = true;
                response.Message = "Success";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
            }
            return(response);
        }
예제 #12
0
        public EResponseBase <Product> Update(Product model)
        {
            EResponseBase <Product> response = new EResponseBase <Product>();

            try
            {
                using (var context = new DataContext())
                {
                    var item = context.Products.Where(x => x.ProductID == model.ProductID).FirstOrDefault();
                    item.Name    = model.Name;
                    item.Stock   = model.Stock;
                    item.Price   = model.Price;
                    item.Remarks = model.Remarks;
                    context.SaveChanges();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #13
0
        public EResponseBase <SalesInvoceDetail> Update(SalesInvoceDetail model)
        {
            EResponseBase <SalesInvoceDetail> response = new EResponseBase <SalesInvoceDetail>();

            try
            {
                using (var context = new DataContext())
                {
                    var item = context.SalesInvoceDetails.Where(x => x.SalesInvoceDetailID == model.SalesInvoceDetailID).FirstOrDefault();
                    item.Price         = model.Price;
                    item.Quantity      = model.Quantity;
                    item.SalesInvoceID = model.SalesInvoceID;
                    item.ProductID     = model.ProductID;
                    context.SaveChanges();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #14
0
        public IHttpActionResult Authenticate(Login_Request login)
        {
            bool isUserValid = false;

            if (login == null)
            {
                throw new HttpResponseException(HttpStatusCode.BadRequest);
            }

            EResponseBase <User> eResponse = UserService.Login(login.Username, login.Password);

            if (eResponse.Code == 200)
            {
                isUserValid = true;
            }
            //TODO: This code is only for demo - extract method in new class & validate correctly in your application !!
            //var isUserValid = (login.Username == "user" && login.Password == "123456");

            if (isUserValid)
            {
                var token = TokenGenerator.GenerateTokenJwt(eResponse.Object.UserName, eResponse.Object.Role);
                return(Ok(token));
            }


            //if (isUserValid)
            //{
            //    var rolename = "Developer";
            //    var token = TokenGenerator.GenerateTokenJwt(login.Username, rolename);
            //    return Ok(token);
            //}

            ////TODO: This code is only for demo - extract method in new class & validate correctly in your application !!
            //var isTesterValid = (login.Username == "test" && login.Password == "123456");
            //if (isTesterValid)
            //{
            //    var rolename = "Tester";
            //    var token = TokenGenerator.GenerateTokenJwt(login.Username, rolename);
            //    return Ok(token);
            //}

            ////TODO: This code is only for demo - extract method in new class & validate correctly in your application !!
            //var isAdminValid = (login.Username == "admin" && login.Password == "123456");
            //if (isAdminValid)
            //{
            //    var rolename = "Administrator";
            //    var token = TokenGenerator.GenerateTokenJwt(login.Username, rolename);
            //    return Ok(token);
            //}

            // Unauthorized access
            return(Unauthorized());
        }
예제 #15
0
        //Filtro por Empleado
        public EResponseBase <CustomBill> GetBySalesMan(String filter)
        {
            EResponseBase <CustomBill> response = new EResponseBase <CustomBill>();

            try
            {
                using (var context = new DataContext())
                {
                    response.List = context.Bills.Join(context.BillDetails, o => o.CustomerID, od => od.BillID,
                                                       (o, od) => new
                    {
                        o,
                        od
                    }).Join(context.SalesMans, c => c.o.SalesManID, e => e.SalesManID,
                            (c, e) => new
                    {
                        c,
                        e
                    }).Where(x => x.e.Name.Equals(filter))
                                    .Select(q => new CustomBill
                    {
                        BillID   = q.c.o.BillID,
                        Code     = q.c.o.Code,
                        Quantity = q.c.od.Quantity,
                        Price    = q.c.od.Price,
                        IGV      = q.c.o.IGV,
                        Subtotal = (q.c.od.Quantity * q.c.od.Price),
                        SalesTax = q.c.o.IGV / 100 * q.c.od.Quantity * q.c.od.Price,
                        Total    = (q.c.od.Quantity * q.c.od.Price) + (q.c.o.IGV / 100 * q.c.od.Quantity * q.c.od.Price),
                    }).ToList();
                }
                response.Status  = true;
                response.Message = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
                return(response);
            }
        }
        public EResponseBase <BillDetail> GetById(int ID)
        {
            EResponseBase <BillDetail> response = new EResponseBase <BillDetail>();

            try
            {
                using (var context = new DataContext())
                {
                    response.Object = context.BillDetails.Find(ID);
                }
                response.Status  = true;
                response.Message = "Success";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
            }
            return(response);
        }
예제 #17
0
        public EResponseBase <Product> Get()
        {
            EResponseBase <Product> response = new EResponseBase <Product>();

            try
            {
                using (var context = new DataContext())
                {
                    response.List = context.Products.ToList();
                }
                response.Status  = true;
                response.Message = "Success";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
            }
            return(response);
        }
예제 #18
0
        public EResponseBase <SalesInvoceDetail> GetList()
        {
            EResponseBase <SalesInvoceDetail> response = new EResponseBase <SalesInvoceDetail>();

            try
            {
                using (var context = new DataContext())
                {
                    response.List = context.SalesInvoceDetails.ToList();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #19
0
        public EResponseBase <SalesInvoceDetail> Get(int ID)
        {
            EResponseBase <SalesInvoceDetail> response = new EResponseBase <SalesInvoceDetail>();

            try
            {
                using (var context = new DataContext())
                {
                    response.List = context.SalesInvoceDetails.Include("Product").Include("SalesInvoce").Where(x => x.SalesInvoceID == ID).ToList();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #20
0
        public EResponseBase <User> GetList()
        {
            EResponseBase <User> response = new EResponseBase <User>();

            try
            {
                using (var context = new DataContext())
                {
                    response.List = context.Users.Where(x => x.State == true).ToList();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #21
0
        public EResponseBase <SalesInvoceSP> GetList()
        {
            EResponseBase <SalesInvoceSP> response = new EResponseBase <SalesInvoceSP>();

            try
            {
                using (var context = new DataContext())
                {
                    response.List = context.Database.SqlQuery <SalesInvoceSP>("pa_listSales").ToList();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #22
0
        public EResponseBase <User> Get(int ID)
        {
            EResponseBase <User> response = new EResponseBase <User>();

            try
            {
                using (var context = new DataContext())
                {
                    response.Object = context.Users.Where(x => x.UserID == ID && x.State == true).FirstOrDefault();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
        public EResponseBase <User> GetUser(User model)
        {
            EResponseBase <User> response = new EResponseBase <User>();

            try
            {
                using (var context = new InvoiceContext())
                {
                    response.Object = context.Users.Where(x => x.Username == model.Username && x.Password == model.Password).FirstOrDefault();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #24
0
        public EResponseBase <Product> Delete(int ID)
        {
            EResponseBase <Product> response = new EResponseBase <Product>();

            try
            {
                using (var context = new DataContext())
                {
                    var customer = context.Products.Find(ID);
                    customer.State = false;
                    context.SaveChanges();
                }
                response.Status  = true;
                response.Message = "Success";
            }
            catch (Exception ex)
            {
                response.Status  = false;
                response.Message = ex.Message;
            }
            return(response);
        }
        public EResponseBase <BillDetail> Delete(int ID)
        {
            EResponseBase <BillDetail> response = new EResponseBase <BillDetail>();

            try
            {
                using (var context = new DataContext())
                {
                    var orderDetail = context.BillDetails.Find(ID);
                    orderDetail.State = false;
                    context.SaveChanges();
                }
                response.Status  = true;
                response.Message = "Success";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
            }
            return(response);
        }
        public EResponseBase <BillDetail> Add(BillDetail orderDetail)
        {
            EResponseBase <BillDetail> response = new EResponseBase <BillDetail>();

            try
            {
                using (var context = new DataContext())
                {
                    orderDetail.State = true;
                    context.BillDetails.Add(orderDetail);
                    context.SaveChanges();
                }
                response.Status  = true;
                response.Message = "Success";
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Status  = false;
            }
            return(response);
        }
예제 #27
0
        public EResponseBase <SalesMan> Delete(int ID)
        {
            EResponseBase <SalesMan> response = new EResponseBase <SalesMan>();

            try
            {
                using (var context = new DataContext())
                {
                    var employee = context.SalesMans.Find(ID);
                    employee.State = false;
                    context.SaveChanges();
                }
                response.Status  = true;
                response.Message = "Success";
            }
            catch (Exception ex)
            {
                response.Status  = false;
                response.Message = ex.Message;
            }
            return(response);
        }
예제 #28
0
        public EResponseBase <SalesInvoceDetail> Add(SalesInvoceDetail model)
        {
            EResponseBase <SalesInvoceDetail> response = new EResponseBase <SalesInvoceDetail>();

            try
            {
                using (var context = new DataContext())
                {
                    model.State = true;
                    context.SalesInvoceDetails.Add(model);
                    context.SaveChanges();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #29
0
        public EResponseBase <SalesInvoceDetail> Delete(int ID)
        {
            EResponseBase <SalesInvoceDetail> response = new EResponseBase <SalesInvoceDetail>();

            try
            {
                using (var context = new DataContext())
                {
                    var item = context.SalesInvoceDetails.Where(x => x.SalesInvoceDetailID == ID).FirstOrDefault();
                    context.SalesInvoceDetails.Remove(item);
                    context.SaveChanges();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }
예제 #30
0
        public EResponseBase <User> Delete(int ID)
        {
            EResponseBase <User> response = new EResponseBase <User>();

            try
            {
                using (var context = new DataContext())
                {
                    var item = context.Users.Where(x => x.UserID == ID).FirstOrDefault();
                    item.State = false;
                    context.SaveChanges();
                }
                response.IsSuccess = true;
                response.Message   = "Success";
                return(response);
            }
            catch (Exception ex)
            {
                response.Message   = ex.Message;
                response.IsSuccess = false;
                return(response);
            }
        }