Exemplo n.º 1
0
        public IHttpActionResult GetCustomer(int id)
        {
            if (id != null)
            {
                CustomerDetails cd = new CustomerDetails();
                using (var db = new OMSEF())
                {
                    var customerDetail = db.CustomerDetails.Where(s => s.CustomerId == id).FirstOrDefault();

                    if (customerDetail != null)
                    {
                        cd.CustomerAge    = customerDetail.CustomerAge;
                        cd.CustomerEmail  = customerDetail.CustomerEmail;
                        cd.CustomerGender = customerDetail.CustomerGender;
                        cd.CustomerId     = customerDetail.CustomerId;
                        cd.CustomerName   = customerDetail.CustomerName;
                        cd.CustomerPhone  = customerDetail.CustomerPhone;
                        cd.UserRoleId     = customerDetail.RoleId;
                    }
                }
                return(Ok(cd));
            }
            else
            {
                return(BadRequest());
            }
        }
        public IHttpActionResult GetAllProducts()
        {
            List <ProductDetails> productDetails = new List <ProductDetails>();

            using (var db = new OMSEF())
            {
                var allProducts = (from a in db.ProductDetails select a).ToList();

                foreach (var a in allProducts)
                {
                    ProductDetails pd = new ProductDetails();
                    pd.availableQuantity = a.AvailableQuantity;
                    pd.barCode           = a.Barcode;
                    pd.height            = a.Height;
                    pd.image             = a.Image;
                    pd.name      = a.Name;
                    pd.productId = a.ProductId;
                    pd.weight    = a.Weight;
                    pd.price     = a.Price;
                    pd.SKU       = a.SKU;

                    productDetails.Add(pd);
                }
            }
            return(Ok(productDetails));
        }
 public IHttpActionResult AddProduct([FromBody] ProductDetails pd)
 {
     if (ModelState.IsValid)
     {
         using (var db = new OMSEF())
         {
             db.ProductDetails.Add(new ProductDetail
             {
                 AvailableQuantity = pd.availableQuantity,
                 Barcode           = pd.barCode,
                 Height            = pd.height,
                 Image             = pd.image,
                 Name   = pd.name,
                 Price  = pd.price,
                 SKU    = pd.SKU,
                 Weight = pd.weight
             });
             db.SaveChanges();
         }
         return(Ok());
     }
     else
     {
         return(BadRequest());
     }
 }
Exemplo n.º 4
0
        public ProductDetails GetIndividualProductDetail(int id)
        {
            if (id != null)
            {
                ProductDetails pd = new ProductDetails();
                using (var db = new OMSEF())
                {
                    var productdetail = db.ProductDetails.Where(s => s.ProductId == id).FirstOrDefault();

                    if (productdetail != null)
                    {
                        pd.availableQuantity = productdetail.AvailableQuantity;
                        pd.barCode           = productdetail.Barcode;
                        pd.height            = productdetail.Height;
                        pd.image             = productdetail.Image;
                        pd.name      = productdetail.Name;
                        pd.productId = productdetail.ProductId;
                        pd.weight    = productdetail.Weight;
                        pd.price     = productdetail.Price;
                        pd.SKU       = productdetail.SKU;
                    }
                }
                return(pd);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
 public IHttpActionResult AddRole([FromBody] UserRoles us)
 {
     using (var db = new OMSEF())
     {
         db.UserRoles.Add(new UserRole
         {
             Name = us.name
         });
         db.SaveChanges();
     }
     return(Ok());
 }
Exemplo n.º 6
0
 public IHttpActionResult DeleteRole(int id)
 {
     using (var db = new OMSEF())
     {
         var userRole = db.UserRoles.Where(s => s.RoleId == id).FirstOrDefault();
         if (userRole != null)
         {
             db.Entry(userRole).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
         }
         return(Ok());
     }
 }
 public IHttpActionResult DeleteAddress(int id)
 {
     using (var db = new OMSEF())
     {
         var shippingAddress = db.ShippingAddresses.Where(s => s.AddressID == id).FirstOrDefault();
         if (shippingAddress != null)
         {
             db.Entry(shippingAddress).State = System.Data.Entity.EntityState.Deleted;
             db.SaveChanges();
         }
         return(Ok());
     }
 }
Exemplo n.º 8
0
        public IHttpActionResult UpdateRole([FromBody] UserRoles us)
        {
            using (var db = new OMSEF())
            {
                var userRole = db.UserRoles.Where(s => s.RoleId == us.roleId).FirstOrDefault();

                if (userRole != null)
                {
                    userRole.Name = us.name;
                }

                db.SaveChanges();
            }
            return(Ok());
        }
Exemplo n.º 9
0
        public IHttpActionResult GetRole(int id)
        {
            UserRoles us = new UserRoles();

            using (var db = new OMSEF())
            {
                var userRole = db.UserRoles.Where(s => s.RoleId == id).FirstOrDefault();

                if (userRole != null)
                {
                    us.name   = userRole.Name;
                    us.roleId = userRole.RoleId;
                }
            }
            return(Ok(us));
        }
 public IHttpActionResult AddAddress([FromBody] ShippingAddresses sa)
 {
     using (var db = new OMSEF())
     {
         db.ShippingAddresses.Add(new ShippingAddress
         {
             Address1 = sa.Address1,
             Address2 = sa.Address2,
             City     = sa.City,
             PinCode  = sa.PinCode,
             State    = sa.State
         });
         db.SaveChanges();
     }
     return(Ok());
 }
Exemplo n.º 11
0
        public IHttpActionResult GetAllRoles()
        {
            List <UserRoles> userRoles = new List <UserRoles>();

            using (var db = new OMSEF())
            {
                var allRoles = (from a in db.UserRoles select a).ToList();

                foreach (var a in allRoles)
                {
                    UserRoles us = new UserRoles();
                    us.name   = a.Name;
                    us.roleId = a.RoleId;
                    userRoles.Add(us);
                }
            }
            return(Ok(userRoles));
        }
        public IHttpActionResult UpdateAddress([FromBody] ShippingAddresses sa)
        {
            using (var db = new OMSEF())
            {
                var shippingAddress = db.ShippingAddresses.Where(s => s.AddressID == sa.AddressID).FirstOrDefault();

                if (shippingAddress != null)
                {
                    shippingAddress.Address1 = sa.Address1;
                    shippingAddress.Address2 = sa.Address2;
                    shippingAddress.City     = sa.City;
                    shippingAddress.PinCode  = sa.PinCode;
                    shippingAddress.State    = sa.State;
                }
                db.SaveChanges();
            }
            return(Ok());
        }
        public IHttpActionResult GetAddress(int id)
        {
            ShippingAddresses sa = new ShippingAddresses();

            using (var db = new OMSEF())
            {
                var userRole = db.ShippingAddresses.Where(s => s.AddressID == id).FirstOrDefault();

                if (userRole != null)
                {
                    sa.Address1  = userRole.Address1;
                    sa.Address2  = userRole.Address2;
                    sa.AddressID = userRole.AddressID;
                    sa.City      = userRole.City;
                    sa.PinCode   = userRole.PinCode;
                    sa.State     = userRole.State;
                }
            }
            return(Ok(sa));
        }
Exemplo n.º 14
0
        public IHttpActionResult DeleteCustomer(int id)
        {
            if (id != null)
            {
                using (var db = new OMSEF())
                {
                    var customerDetail = db.CustomerDetails.Where(s => s.CustomerId == id).FirstOrDefault();
                    if (customerDetail != null)
                    {
                        db.Entry(customerDetail).State = System.Data.Entity.EntityState.Deleted;
                        db.SaveChanges();
                    }

                    return(Ok());
                }
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 15
0
        public IHttpActionResult AddCustomer([FromBody] CustomerDetails cd)
        {
            using (var db = new OMSEF())
            {
                var customer = new CustomerDetail();

                customer.CustomerAge    = cd.CustomerAge;
                customer.CustomerEmail  = cd.CustomerEmail;
                customer.CustomerGender = cd.CustomerGender;
                customer.CustomerPhone  = cd.CustomerPhone;
                customer.Password       = cd.Password;
                customer.CustomerName   = cd.CustomerName;
                customer.RoleId         = cd.UserRoleId;

                db.CustomerDetails.Add(customer);

                db.SaveChanges();
            }

            return(Ok());
        }
Exemplo n.º 16
0
        public IHttpActionResult GetAllCustomers()
        {
            List <CustomerDetails> customerDetails = new List <CustomerDetails>();

            using (var db = new OMSEF())
            {
                var allCustomers = (from a in db.CustomerDetails select a).ToList();
                foreach (var a in allCustomers)
                {
                    CustomerDetails cd = new CustomerDetails();
                    cd.CustomerAge    = a.CustomerAge;
                    cd.CustomerEmail  = a.CustomerEmail;
                    cd.CustomerGender = a.CustomerGender;
                    cd.CustomerId     = a.CustomerId;
                    cd.CustomerName   = a.CustomerName;
                    cd.CustomerPhone  = a.CustomerPhone;
                    cd.UserRoleId     = a.RoleId;
                    customerDetails.Add(cd);
                }
            }
            return(Ok(customerDetails));
        }
        public IHttpActionResult UpdateProduct([FromBody] ProductDetails pd)
        {
            bool isUpdated = false;

            if (ModelState.IsValid)
            {
                using (var db = new OMSEF())
                {
                    var productdetail = db.ProductDetails.Where(s => s.ProductId == pd.productId).FirstOrDefault();

                    if (productdetail != null)
                    {
                        productdetail.AvailableQuantity = pd.availableQuantity;
                        productdetail.Barcode           = pd.barCode;
                        productdetail.Height            = pd.height;
                        productdetail.Image             = pd.image;
                        productdetail.Name   = pd.name;
                        productdetail.Price  = pd.price;
                        productdetail.SKU    = pd.SKU;
                        productdetail.Weight = pd.weight;
                        db.SaveChanges();
                        isUpdated = true;
                    }
                }
                if (isUpdated)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
            else
            {
                return(BadRequest());
            }
        }
Exemplo n.º 18
0
        public IHttpActionResult UpdateCustomer([FromBody] CustomerDetails cd)
        {
            bool isUpdated = false;

            if (ModelState.IsValid)
            {
                using (var db = new OMSEF())
                {
                    var customerDetail = db.CustomerDetails.Where(s => s.CustomerId == cd.CustomerId).FirstOrDefault();

                    if (customerDetail != null)
                    {
                        customerDetail.CustomerAge    = cd.CustomerAge;
                        customerDetail.CustomerEmail  = cd.CustomerEmail;
                        customerDetail.CustomerGender = cd.CustomerGender;
                        customerDetail.CustomerPhone  = cd.CustomerPhone;
                        customerDetail.Password       = cd.Password;
                        customerDetail.CustomerName   = cd.CustomerName;
                        customerDetail.RoleId         = cd.UserRoleId;

                        db.SaveChanges();
                        isUpdated = true;
                    }
                }
                if (isUpdated)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
            else
            {
                return(BadRequest());
            }
        }
        public IHttpActionResult GetallAddresses()
        {
            List <ShippingAddresses> shippingAddresses = new List <ShippingAddresses>();

            using (var db = new OMSEF())
            {
                var allAddresses = (from a in db.ShippingAddresses select a).ToList();

                foreach (var a in allAddresses)
                {
                    ShippingAddresses sa = new ShippingAddresses();
                    sa.Address1  = a.Address1;
                    sa.Address2  = a.Address2;
                    sa.AddressID = a.AddressID;
                    sa.City      = a.City;
                    sa.PinCode   = a.PinCode;
                    sa.State     = a.State;

                    shippingAddresses.Add(sa);
                }
            }
            return(Ok(shippingAddresses));
        }
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            IEnumerable <string> userHeader = request.Headers.GetValues("username");
            var userName = userHeader.FirstOrDefault();

            IEnumerable <string> passwordHeader = request.Headers.GetValues("password");
            var passWord = passwordHeader.FirstOrDefault();

            string[] roleDB = new string[1];
            string[] role   = new string[1];
            using (var db = new OMSEF())
            {
                var roleid = (from d in db.CustomerDetails
                              where d.CustomerEmail == userName && d.Password == passWord
                              select d.RoleId).FirstOrDefault();

                if (roleid != 0)
                {
                    roleDB = (from r in db.UserRoles
                              where r.RoleId == roleid
                              select r.Name).ToArray();

                    foreach (var r in roleDB)
                    {
                        // role[0] = r.Replace(' ', '');
                        role[0] = r.Trim();
                    }

                    var identity = new GenericIdentity(userName);
                    SetPrincipal(new GenericPrincipal(identity, role));
                }
            }
            //string role1 = "Admin";
            //string[] role = new string[] { "Admin" };
            return(base.SendAsync(request, cancellationToken));
        }