Beispiel #1
0
        public JsonResult SaveProduct(Product product)
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            bool isSuccess          = true;

            if (product.ProductId > 0)
            {
                db.Entry(product).State = EntityState.Modified;
            }
            else
            {
                product.Status = 1;
                product.Name   = "aaa";
                db.Products.Add(product);
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                isSuccess = false;
            }

            return(Json(isSuccess, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveInvoiceSale(Sale sale, List <SalesDetail> salesDetails)
        {
            PointOfSale.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage();
            POS_TutorialEntities db = new POS_TutorialEntities();

            retMessage.IsSuccess = true;

            foreach (var item in salesDetails)
            {
                sale.SalesDetails.Add(new SalesDetail {
                    ProductId = item.ProductId, UnitPrice = item.UnitPrice, Quantity = item.Quantity, LineTotal = item.LineTotal
                });
                var prd = db.ProductStocks.Where(x => x.ProductId == item.ProductId && x.Quantity > 0).FirstOrDefault();
                prd.Quantity        = prd.Quantity - item.Quantity;
                db.Entry(prd).State = EntityState.Modified;
            }
            db.Sales.Add(sale);
            retMessage.Messagae = "Save Success!";
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                retMessage.IsSuccess = false;
            }

            return(Json(retMessage, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveProductStock(ProductStock stock)
        {
            PointOfSale.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage();
            POS_TutorialEntities db = new POS_TutorialEntities();

            retMessage.IsSuccess = true;

            if (stock.ProductQtyId > 0)
            {
                db.Entry(stock).State = EntityState.Modified;
                retMessage.Messagae   = "Update Success!";
            }
            else
            {
                db.ProductStocks.Add(stock);
                retMessage.Messagae = "Save Success!";
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                retMessage.IsSuccess = false;
            }

            return(Json(retMessage, JsonRequestBehavior.AllowGet));
        }
Beispiel #4
0
        public JsonResult SaveUser(User user)
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            bool isSuccess          = true;

            if (user.UserId > 0)
            {
                db.Entry(user).State = EntityState.Modified;
            }
            else
            {
                user.Status   = 1;
                user.Password = AppHelper.GetMd5Hash(user.Password);
                db.Users.Add(user);
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                isSuccess = false;
            }

            return(Json(isSuccess, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetInvoiceBySalesId(int salesId)
        {
            POS_TutorialEntities db       = new POS_TutorialEntities();
            List <Sale>          dataList = (from sd in db.SalesDetails.ToList()
                                             join s in db.Sales on sd.SalesId equals s.SalesId
                                             where sd.SalesId == salesId
                                             select new Sale {
                SalesId = (int)sd.SalesId,
                OrderNo = s.OrderNo,
                CustomerName = s.CustomerName,
                CustomerPhone = s.CustomerPhone,
                CustomerAddress = s.CustomerAddress,
                OrderDate = s.OrderDate,
                PaymentMethod = s.PaymentMethod,
                TotalAmout = s.TotalAmout,
                SalesDetailId = sd.SalesDetailId,
                ProductId = sd.ProductId,
                UnitPrice = sd.UnitPrice,
                Subtotal = s.Subtotal,
                Quantity = sd.Quantity,
                LineTotal = sd.LineTotal,
                DiscountParcentage = s.DiscountParcentage,
                VatParcentage = s.VatParcentage
            }).ToList();

            return(Json(dataList, JsonRequestBehavior.AllowGet));
        }
Beispiel #6
0
        public JsonResult GetAllUser()
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            var dataList            = db.Users.Where(x => x.Status == 1).ToList();

            return(Json(dataList, JsonRequestBehavior.AllowGet));
        }
Beispiel #7
0
        public JsonResult GetAllCategory()
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            var dataList            = db.Categories.Where(x => x.Status == 1).ToList();

            return(Json(dataList, JsonRequestBehavior.AllowGet));

            //string json = JsonConvert.SerializeObject(dataList, Formatting.None);
            //return Json(json, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetAllBatch()
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            var dataList            = db.Batches.ToList();
            var modefiedData        = dataList.Select(x => new
            {
                BatchId   = x.BatchId,
                BatchName = x.BatchName,
            }).ToList();

            return(Json(modefiedData, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetAllGetegory()
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            var dataList            = db.Categories.Where(x => x.Status == 1).ToList();
            var data = dataList.Select(x => new
            {
                CategoryId = x.CategoryId,
                Name       = x.Name,
                Status     = x.Status
            });

            return(Json(data, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetAllProduct()
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            var dataList            = db.Products.Include("Category").ToList();
            var modefiedData        = dataList.Select(x => new
            {
                ProductId    = x.ProductId,
                CategoryId   = x.CategoryId,
                Name         = x.Name,
                Status       = x.Status,
                CategoryName = x.Category.Name
            }).ToList();

            return(Json(modefiedData, JsonRequestBehavior.AllowGet));
        }
        public JsonResult EditInvoiceSale(Sale sale, List <SalesDetail> salesDetails, List <int> deleted)
        {
            PointOfSale.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage();
            POS_TutorialEntities db = new POS_TutorialEntities();

            retMessage.IsSuccess = true;

            if (deleted != null)
            {
                foreach (var item in deleted)
                {
                    var data = db.SalesDetails.Where(x => x.SalesDetailId == item).SingleOrDefault();;
                    db.SalesDetails.Remove(data);
                }
            }

            foreach (var item in salesDetails)
            {
                if (item.SalesDetailId > 0)
                {
                    db.Entry(item).State = EntityState.Modified;
                    retMessage.Messagae  = "Update Success!";
                }
                else
                {
                    sale.SalesDetails.Add(new SalesDetail {
                        ProductId = item.ProductId, UnitPrice = item.UnitPrice, Quantity = item.Quantity, LineTotal = item.LineTotal
                    });
                    var prd = db.ProductStocks.Where(x => x.ProductId == item.ProductId && x.Quantity > 0).FirstOrDefault();
                    prd.Quantity        = prd.Quantity - item.Quantity;
                    db.Entry(prd).State = EntityState.Modified;
                    db.Sales.Add(sale);
                    retMessage.Messagae = "Save Success!";
                }
            }


            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                retMessage.IsSuccess = false;
            }

            return(Json(retMessage, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetAllSales()
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            var dataList            = db.Sales.ToList();
            var modefiedData        = dataList.Select(x => new
            {
                SalesId         = x.SalesId,
                OrderNo         = x.OrderNo,
                CustomerName    = x.CustomerName,
                CustomerPhone   = x.CustomerPhone,
                CustomerAddress = x.CustomerAddress,
                OrderDate       = x.OrderDate,
                TotalAmout      = x.TotalAmout
            }).ToList();

            return(Json(modefiedData, JsonRequestBehavior.AllowGet));
        }
Beispiel #13
0
        public override void OnAuthorization(AuthorizationContext authorizationContext)
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            string username         = Convert.ToString(System.Web.HttpContext.Current.Session["Username"]);
            string role             = Convert.ToString(System.Web.HttpContext.Current.Session["Role"]);

            string actionName     = authorizationContext.ActionDescriptor.ActionName;
            string controllerName = authorizationContext.ActionDescriptor.ControllerDescriptor.ControllerName;
            string tag            = controllerName + actionName;

            // tag = controller + action
            // tag = "HOME" + "Index"

            if (authorizationContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true) ||
                authorizationContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true))
            {
                // Don't check for authorization as AllowAnonymous filter is applied to the action or controller
                return;
            }

            // Check for authorization
            if (System.Web.HttpContext.Current.Session["Username"] == null)
            {
                authorizationContext.Result = new HttpUnauthorizedResult();
            }
            if (username != null && username != "")
            {
                bool isPermitted = false;

                var viewPermission = db.RolePermissions.Where(x => x.Role == role && x.Tag == tag).SingleOrDefault();
                if (viewPermission != null)
                {
                    isPermitted = true;
                }
                if (isPermitted == false)
                {
                    authorizationContext.Result = new RedirectToRouteResult(
                        new RouteValueDictionary
                    {
                        { "controller", "Home" },
                        { "action", "AccessDenied" }
                    });
                }
            }
        }
        public JsonResult GetAllProductStocks()
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            var dataList            = db.ProductStocks.Include("Product").Include("Batch").ToList();
            var modefiedData        = dataList.Select(x => new
            {
                ProductQtyId  = x.ProductQtyId,
                ProductId     = x.ProductId,
                ProductName   = x.Product.Name,
                Quantity      = x.Quantity,
                BatchId       = x.BatchId,
                BatchName     = x.Batch.BatchName,
                PurchasePrice = x.PurchasePrice,
                SalesPrice    = x.SalesPrice
            }).ToList();

            return(Json(modefiedData, JsonRequestBehavior.AllowGet));
        }
Beispiel #15
0
        public JsonResult CheckLogin(string username, string password)
        {
            POS_TutorialEntities db  = new POS_TutorialEntities();
            string md5StringPassword = AppHelper.GetMd5Hash(password);
            var    dataItem          = db.Users.Where(x => x.Username == username && x.Password == md5StringPassword).SingleOrDefault();
            bool   isLogged          = true;

            if (dataItem != null)
            {
                Session["Username"] = dataItem.Username;
                Session["Role"]     = dataItem.Role;
                isLogged            = true;
            }
            else
            {
                isLogged = false;
            }
            return(Json(isLogged, JsonRequestBehavior.AllowGet));
        }
        public JsonResult GetAllProduct()
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            var dataList            = (from prd in db.Products.Include("Category").ToList()
                                       join stk in db.ProductStocks on prd.ProductId equals stk.ProductId
                                       where stk.Quantity > 0
                                       select new
            {
                ProductId = prd.ProductId,
                CategoryId = prd.CategoryId,
                Name = prd.Name,
                Status = prd.Status,
                CategoryName = prd.Category.Name,
                PurchasePrice = stk.PurchasePrice,
                SalesPrice = stk.SalesPrice
            }).ToList();


            return(Json(dataList, JsonRequestBehavior.AllowGet));
        }
        public JsonResult SaveBatch(Batch batch)
        {
            PointOfSale.Helper.AppHelper.ReturnMessage retMessage = new AppHelper.ReturnMessage();
            POS_TutorialEntities db = new POS_TutorialEntities();

            retMessage.IsSuccess = true;

            if (batch.BatchId > 0)
            {
                db.Entry(batch).State = EntityState.Modified;
                retMessage.Messagae   = "Update Success!";
            }
            else
            {
                batch.BatchName = batch.BatchName + db.Batches.Count();
                var batchData = db.Batches.Where(x => x.BatchName.Equals(batch.BatchName)).SingleOrDefault();
                if (batchData == null)
                {
                    db.Batches.Add(batch);
                    retMessage.Messagae = "Save Success!";
                }
                else
                {
                    retMessage.IsSuccess = false;
                    retMessage.Messagae  = "This batch already exist!Please refresh and again try!";
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                retMessage.IsSuccess = false;
            }

            return(Json(retMessage, JsonRequestBehavior.AllowGet));
        }
Beispiel #18
0
        public JsonResult SaveCategory(Category cat)
        {
            POS_TutorialEntities db = new POS_TutorialEntities();
            bool isSuccess          = true;

            if (cat.CategoryId > 0)
            {
                db.Entry(cat).State = EntityState.Modified;
            }
            else
            {
                cat.Status = 1;
                db.Categories.Add(cat);
            }
            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                isSuccess = false;
            }
            return(Json(isSuccess, JsonRequestBehavior.AllowGet));
        }