Exemplo n.º 1
0
        /// <summary>
        /// Add supplier carton details
        /// </summary>
        /// <param name="supplierCarton"></param>
        /// <returns></returns>
        public JsonResult AddSupplierCartoonDetails(SupplierCartoon supplierCartoon)
        {
            SupplierCartoon data = new SupplierCartoon();

            try
            {
                using (var db = new ArityEntities())
                {
                    data.CartoonBM             = supplierCartoon.CartoonBM;
                    data.CartoonNumber         = supplierCartoon.CartoonNumber;
                    data.CartoonSize           = supplierCartoon.CartoonSize;
                    data.CreatedDate           = DateTime.UtcNow;
                    data.GrossWeight           = supplierCartoon.GrossWeight;
                    data.ModifiedDate          = DateTime.UtcNow;
                    data.NetWeight             = supplierCartoon.NetWeight;
                    data.PcsPerCartoon         = supplierCartoon.PcsPerCartoon;
                    data.Status                = supplierCartoon.Status;
                    data.SupplierAssignedMapId = supplierCartoon.SupplierAssignedMapId;
                    data.TotalCartoons         = supplierCartoon.TotalCartoons;
                    data.TotalGrossWeight      = supplierCartoon.TotalGrossWeight;
                    data.TotalNetWeight        = supplierCartoon.TotalNetWeight;
                    db.SupplierCartoons.Add(data);
                    db.SaveChanges();
                }
                return(Json(new { data = data }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public ActionResult Create(int?Id)
        {
            try
            {
                Product       product     = new Product();
                ArityEntities dataContext = new ArityEntities();
                int[]         parentIds   = null;
                int[]         supplierIds = null;
                product = dataContext.Products.Where(x => x.Id == Id).FirstOrDefault();
                if (product != null)
                {
                    parentIds   = !string.IsNullOrWhiteSpace(product.ParentIds) ? Array.ConvertAll(product.ParentIds.Split(','), int.Parse) : null;
                    supplierIds = !string.IsNullOrWhiteSpace(product.Suppliers) ? Array.ConvertAll(product.Suppliers.Split(','), int.Parse) : null;
                }
                ViewBag.productList = product == null ? new MultiSelectList(dataContext.Products.Where(x => x.Parent_Id == 0 && x.IsActive == true).ToList(), "Id", "English_Name") : new MultiSelectList(dataContext.Products.Where(x => x.Parent_Id == 0).ToList(), "Id", "English_Name", parentIds);
                var suppliers = dataContext.Users.Where(x => x.UserType == 5 && x.IsActive == true && x.CompanyName != "").Select(s => new
                {
                    Id           = s.Id,
                    SupplierName = s.CompanyName
                }).ToList();
                ViewBag.supplierList = product == null || supplierIds == null || supplierIds.Count() == 0 ? new MultiSelectList(suppliers, "Id", "SupplierName") : new MultiSelectList(suppliers, "Id", "SupplierName", supplierIds);

                ProductDetails productModel = ConvertModeltoDTO(product);

                return(View(productModel));
            }

            catch (Exception ex)
            {
                var exception = ex;
                return(View());
            }
        }
Exemplo n.º 3
0
        public ActionResult ProductList()
        {
            ArityEntities dataContext = new ArityEntities();

            var productList = (from product in dataContext.Products.ToList().Where(_ => _.Parent_Id == 0)
                               select new
            {
                Id = product.Id,
                Chinese_Name = product.Chinese_Name,
                English_Name = product.English_Name,
                Quantity = product.Quantity,
                Dollar_Price = product.Dollar_Price,
                RMB_Price = product.RMB_Price,
                Unit = product.Unit,
                Description = product.Description,
                ModifiedDate = product.ModifiedDate.GetValueOrDefault().ToString("MM/dd/yyyy h:m tt"),
                ChildProducts = (from subProcduct in dataContext.Products.ToList().Where(_ => _.Parent_Id == product.Id)
                                 select new
                {
                    Id = subProcduct.Id,
                    Chinese_Name = subProcduct.Chinese_Name,
                    English_Name = subProcduct.English_Name,
                    Quantity = subProcduct.Quantity,
                    Dollar_Price = subProcduct.Dollar_Price,
                    RMB_Price = subProcduct.RMB_Price,
                    Unit = subProcduct.Unit,
                    Description = subProcduct.Description,
                    ModifiedDate = subProcduct.ModifiedDate.GetValueOrDefault().ToString("MM/dd/yyyy h:m tt")
                }).ToList()
            }).ToList();

            return(Json(new { data = productList }, JsonRequestBehavior.AllowGet));
            ///return View(productList,JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get product for order
        /// </summary>
        /// <param name="id"></param>
        /// <param name="qty"></param>
        /// <returns></returns>
        public JsonResult AddProductToCart(int id, int qty)
        {
            ArityEntities objDb   = new ArityEntities();
            var           product = (from pro in objDb.Products.ToList()
                                     where pro.Id == id
                                     select new Product
            {
                Dollar_Price = pro.Dollar_Price
            }).FirstOrDefault();
            var items = objDb.Products.Where(_ => _.Id == id).Union(objDb.Products.Where(_ => _.Parent_Id == id)).ToList();

            items.ForEach(_ => _.Quantity = qty);
            var productList = (from lst in items
                               select new Product
            {
                English_Name = lst.English_Name,
                Chinese_Name = lst.Chinese_Name,
                Dollar_Price = lst.Dollar_Price,
                RMB_Price = lst.RMB_Price,
                Quantity = lst.Quantity,
                Id = lst.Id,
                Parent_Id = lst.Parent_Id
            }).ToList();

            return(Json(new { data = productList }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
        public ActionResult Login(LoginModel entity)
        {
            try
            {
                using (var db = new ArityEntities())
                {
                    if (!ModelState.IsValid)
                    {
                        return(View(entity));
                    }
                    //check user credentials
                    var userInfo = db.Users.Where(s => s.EmailId == entity.Email.Trim() && s.Password == entity.Password.Trim()).FirstOrDefault();

                    if (userInfo != null)
                    {
                        FormsAuthentication.SetAuthCookie(entity.Email, true);
                        //Set A Unique name in session
                        Session["Username"] = entity.Email;
                        return(RedirectToAction("OrderList", "Order", "Order"));
                    }
                    else
                    {
                        //Login Fail
                        TempData["ErrorMSG"] = "Access Denied! Wrong Credential";
                        return(View(entity));
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 6
0
        public ActionResult Create(Product product)
        {
            ArityEntities dataContext = new ArityEntities();

            if (product != null && product.Id > 0)
            {
                var existingProduct = dataContext.Products.Where(_ => _.Id == product.Id).FirstOrDefault();
                existingProduct.Chinese_Name = product.Chinese_Name;
                existingProduct.English_Name = product.English_Name;
                existingProduct.Quantity     = product.Quantity;
                existingProduct.Unit         = product.Unit;
                existingProduct.Dollar_Price = product.Dollar_Price;
                existingProduct.RMB_Price    = product.RMB_Price;
                existingProduct.Parent_Id    = product.Parent_Id == null ? existingProduct.Parent_Id : product.Parent_Id;
            }
            else
            {
                if (product.Parent_Id == null)
                {
                    product.Parent_Id = 0;
                }
                dataContext.Products.Add(product);
            }
            dataContext.SaveChanges();
            return(RedirectToAction("list", "product"));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Place order landing page
        /// </summary>
        /// <returns></returns>
        public ActionResult MakeOrder()
        {
            ArityEntities objDb = new ArityEntities();

            ViewBag.Products = new SelectList(objDb.Products.Where(_ => _.Parent_Id == 0).ToList(), "Id", "English_Name");
            return(View());
        }
Exemplo n.º 8
0
        /// <summary>
        /// Add supplier order line items
        /// </summary>
        /// <param name="SupplierOrderLineItemModel"></param>
        /// <returns></returns>
        public JsonResult AddSupplierOrderLineItems(SupplierOrderLineItemModel model)
        {
            Supplier_Assigned_OrderLineItem data = new Supplier_Assigned_OrderLineItem();

            try
            {
                if (model != null)
                {
                    using (var db = new ArityEntities())
                    {
                        data.OrderSupplierMapId = model.OrderSupplierMapId;
                        data.Quantity           = model.Quantity;
                        data.Status             = "Draft";
                        data.SupplierId         = model.SupplierId;
                        data.CreatedDate        = DateTime.UtcNow;
                        data.ModifiedDate       = DateTime.UtcNow;
                        db.Supplier_Assigned_OrderLineItem.Add(data);
                        db.SaveChanges();
                    }
                }
                return(Json(new { data = data }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 9
0
        public ActionResult Login(LoginModel entity)
        {
            try
            {
                using (var db = new ArityEntities())
                {
                    if (!ModelState.IsValid)
                    {
                        return(View(entity));
                    }
                    //check user credentials
                    var userInfo = db.Users.Where(s => s.EmailId == entity.Email.Trim() && s.Password == entity.Password.Trim()).FirstOrDefault();

                    if (userInfo != null && userInfo.IsActive == true)
                    {
                        FormsAuthentication.SetAuthCookie(entity.Email, true);
                        //Set A Unique name in cookie
                        var Username = new HttpCookie("Username");
                        Username.Value   = userInfo.EmailId;
                        Username.Expires = DateTime.Now.AddDays(7d);
                        var UserType = new HttpCookie("UserType");
                        UserType.Value   = userInfo.UserType.ToString();
                        UserType.Expires = DateTime.Now.AddDays(7d);
                        var UserId = new HttpCookie("UserId");
                        UserId.Value   = userInfo.Id.ToString();
                        UserId.Expires = DateTime.Now.AddDays(7d);
                        Response.Cookies.Add(Username);
                        Response.Cookies.Add(UserType);
                        Response.Cookies.Add(UserId);
                        //Session["Username"] = userInfo.EmailId;
                        //Session["UserType"] = userInfo.UserType;
                        //Session["UserId"] = userInfo.Id;
                        if (!string.IsNullOrEmpty(entity.ReturnURL))
                        {
                            return(RedirectToAction(entity.ReturnURL));
                        }
                        if (userInfo.UserType == (int)AritySystems.Common.EnumHelpers.UserType.Admin)
                        {
                            return(RedirectToAction("orders", "order"));
                        }
                        else if (userInfo.UserType == (int)AritySystems.Common.EnumHelpers.UserType.Supplier)
                        {
                            return(RedirectToAction("suppliersorder", "order"));
                        }
                        return(RedirectToAction("orderlist", "order"));
                    }
                    else
                    {
                        //Login Fail
                        TempData["ErrorMSG"] = "Access Denied! Wrong Credential or User is not Active";
                        return(View(entity));
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Get Product details by Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult GetProductDetail(int id)
        {
            ArityEntities objDb   = new ArityEntities();
            var           product = (from pro in objDb.Products.ToList()
                                     where pro.Id == id
                                     select new Product
            {
                Dollar_Price = pro.Dollar_Price
            }).FirstOrDefault();

            return(Json(product, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 11
0
        public ActionResult Delete(int?id)
        {
            ArityEntities dataContext = new ArityEntities();

            id = id ?? 0;
            var product = dataContext.Products.Where(x => x.Id == id).FirstOrDefault();

            if (product != null)
            {
            }

            return(View());
        }
Exemplo n.º 12
0
        public ActionResult Create(ProductDetails product)
        {
            string productParentIds = string.Empty;
            string suppliers        = string.Empty;
            int    parent           = 0;

            if (product.ParentIdsArray != null)
            {
                productParentIds = string.Join(",", product.ParentIdsArray);
                parent           = 1;
            }
            if (product.SuppliersArray != null)
            {
                suppliers = string.Join(",", product.SuppliersArray);
            }

            ArityEntities dataContext = new ArityEntities();

            if (product != null && product.Id > 0)
            {
                var existingProduct = dataContext.Products.Where(_ => _.Id == product.Id).FirstOrDefault();
                existingProduct.Chinese_Name = product.Chinese_Name;
                existingProduct.English_Name = product.English_Name;
                existingProduct.Quantity     = product.Quantity;
                existingProduct.Unit         = product.Unit;
                existingProduct.Dollar_Price = product.Dollar_Price;
                existingProduct.RMB_Price    = product.RMB_Price;
                existingProduct.Parent_Id    = parent;
                existingProduct.Description  = product.Description;
                existingProduct.ModifiedDate = DateTime.Now;
                existingProduct.ParentIds    = productParentIds;
                existingProduct.Suppliers    = suppliers;
                existingProduct.IsActive     = true;
                existingProduct.BOM          = product.BOM;
                existingProduct.Weight       = product.Weight;
                existingProduct.CBM          = product.Cubic_Meter;
            }
            else
            {
                product.Parent_Id    = parent;
                product.ParentIds    = productParentIds;
                product.ModifiedDate = DateTime.Now;
                product.CreatedDate  = DateTime.Now;
                product.IsActive     = true;
                var data = ConvertDTOtoModel(product);
                dataContext.Products.Add(ConvertDTOtoModel(product));
            }
            dataContext.SaveChanges();
            return(RedirectToAction("list", "product"));
        }
Exemplo n.º 13
0
        public ActionResult Delete(int?id)
        {
            ArityEntities dataContext = new ArityEntities();

            id = id ?? 0;
            var product = dataContext.Products.Where(x => x.Id == id).FirstOrDefault();

            if (product != null)
            {
                product.IsActive = false;
                dataContext.SaveChanges();
            }

            return(RedirectToAction("List"));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Get order details for customer
        /// </summary>
        /// <returns></returns>
        public JsonResult GetOrderList()
        {
            ArityEntities objDb    = new ArityEntities();
            var           orderLst = (from order in objDb.Orders.OrderByDescending(_ => _.CreatedDate).ToList()
                                      select new
            {
                Id = order.Id,
                Prefix = order.Prefix,
                CreatedDate = order.CreatedDate.GetValueOrDefault().ToString("MM/dd/yyyy h:m tt"),
                Status = order.Status,
                TotalItem = order.OrderLineItems.Sum(_ => _.Quantity),
                Total = order.OrderLineItems.Sum(_ => (_.DollarPurchasePrice * _.Quantity))
            }).ToList();

            return(Json(new { data = orderLst }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 15
0
        public ActionResult Create(int?Id)
        {
            try
            {
                Product       product     = new Product();
                ArityEntities dataContext = new ArityEntities();
                product             = dataContext.Products.Where(x => x.Id == Id).FirstOrDefault();
                ViewBag.productList = product == null ? new SelectList(dataContext.Products.Where(x => x.Parent_Id == 0).ToList(), "Id", "English_Name") : new SelectList(dataContext.Products.Where(x => x.Parent_Id == 0).ToList(), "Id", "English_Name", product.Parent_Id ?? 0);
                return(View(product));
            }

            catch (Exception ex)
            {
                var exception = ex;
                return(View());
            }
        }
Exemplo n.º 16
0
        public ActionResult MakeOrder(FormCollection fc)
        {
            ArityEntities objDb = new ArityEntities();
            List <KeyValuePair <int, int> > lineItem = new List <KeyValuePair <int, int> >();

            ViewBag.Products = new SelectList(objDb.Products.Where(_ => _.Parent_Id == 0).ToList(), "Id", "English_Name");
            if (fc != null)
            {
                try
                {
                    for (int i = 1; i <= 999999; i++)
                    {
                        if (fc["productId_" + i] == null && fc["qty_" + i] == null)
                        {
                            break;
                        }
                        lineItem.Add(new KeyValuePair <int, int>(Convert.ToInt32(fc["productId_" + i]), Convert.ToInt32(fc["qty_" + i])));
                    }
                    if (lineItem.Any())
                    {
                        var order = objDb.Orders.Add(new Order()
                        {
                            CustomerId = 1, CreatedDate = DateTime.Now, Prefix = "user1", Status = "1"
                        });
                        objDb.SaveChanges();
                        foreach (var item in lineItem.Where(_ => _.Value > 0))
                        {
                            var prodcut = objDb.Products.Where(_ => _.Id == item.Key).FirstOrDefault();
                            objDb.OrderLineItems.Add(new OrderLineItem()
                            {
                                OrderId = order.Id, ProductId = prodcut.Id, DollarPurchasePrice = prodcut.Dollar_Price, RMDPurchasePrice = prodcut.RMB_Price, Quantity = item.Value
                            });
                        }
                        objDb.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    TempData["Error"] = "Error occured while place your order. Please try again.";
                    return(View());
                }
            }
            TempData["Success"] = "Order Placed. Thank you";
            return(View());
        }
Exemplo n.º 17
0
        private List <ProductDetails> GetChildProducts(int parentId)
        {
            ArityEntities         dataContext      = new ArityEntities();
            List <ProductDetails> childProductList = new List <ProductDetails>();

            var parentsCsv = (from data in dataContext.Products
                              where data.ParentIds != null && data.ParentIds != string.Empty && data.IsActive
                              select new
            {
                Id = data.Id,
                parents = data.ParentIds
            }).ToList();

            foreach (var data in parentsCsv)
            {
                var ids = data.parents.Split(new[] { ',' })
                          .Select(x => int.Parse(x))
                          .ToArray();

                var childProductDetails = (from childProduct in dataContext.Products.ToList().Where(x => ids.Contains(parentId) && x.Id == data.Id)
                                           select new ProductDetails()
                {
                    Id = childProduct.Id,
                    Chinese_Name = childProduct.Chinese_Name,
                    Description = childProduct.Description,
                    Dollar_Price = childProduct.Dollar_Price,
                    ModifiedDate = childProduct.ModifiedDate,
                    English_Name = childProduct.English_Name,
                    Quantity = childProduct.Quantity,
                    RMB_Price = childProduct.RMB_Price,
                    Unit = getEnumValue(childProduct.Unit),
                    BOM = GetBOMForParent(parentId, childProduct.Id)
                }).FirstOrDefault();



                if (childProductDetails != null)
                {
                    childProductList.Add(childProductDetails);
                }
            }

            return(childProductList);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Order Line Item list and supplier order line item list with order details
        /// </summary>
        /// <param name="OrderId"></param>
        /// <returns></returns>
        public ActionResult OrderLineItems(int OrderId)
        {
            OrderDetailModel model = new OrderDetailModel();

            try
            {
                using (var db = new ArityEntities())
                {
                    model.OrderName          = db.Orders.Where(x => x.Id == OrderId).Select(x => x.Prefix).FirstOrDefault();
                    model.OrderDate          = db.Orders.Where(x => x.Id == OrderId).Select(x => x.CreatedDate).FirstOrDefault() ?? DateTime.MinValue;
                    model.Status             = db.Orders.Where(x => x.Id == OrderId).Select(x => x.Status).FirstOrDefault();
                    model.OrderLineItemsList = db.OrderLineItems.Where(x => x.OrderId == OrderId).ToList();
                    foreach (var item in model.OrderLineItemsList)
                    {
                        model.OrderTotal = item.DollarPurchasePrice * item.Quantity ?? 0;
                    }
                    model.SupplierOrderLineItemList = (from a in db.Supplier_Assigned_OrderLineItem
                                                       join b in db.OrderLineItem_Supplier_Mapping on a.OrderSupplierMapId equals b.Id
                                                       join c in db.OrderLineItems on b.OrderLineItemId equals c.Id
                                                       join d in db.Orders on c.OrderId equals d.Id
                                                       where d.Id == OrderId
                                                       select new SupplierOrderLineItemModel
                    {
                        Id = a.Id,
                        CreatedDate = a.CreatedDate,
                        ModifiedDate = a.ModifiedDate,
                        OrderSupplierMapId = a.OrderSupplierMapId,
                        Order_Prefix = d.Prefix,
                        Quantity = a.Quantity,
                        Status = a.Status,
                        SupplierId = a.SupplierId,
                        SupplierName = b.User.UserName
                    }).ToList();
                }
                return(Json(new { data = model }, JsonRequestBehavior.AllowGet));
                //return View(model);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 19
0
        public ActionResult ProductList()
        {
            ArityEntities dataContext = new ArityEntities();

            var productList = (from product in dataContext.Products.ToList().Where(_ => _.Parent_Id == 0 && Convert.ToBoolean(_.IsActive))
                               select new
            {
                Id = product.Id,
                Chinese_Name = product.Chinese_Name,
                English_Name = product.English_Name,
                Quantity = product.Quantity,
                Dollar_Price = product.Dollar_Price,
                RMB_Price = product.RMB_Price,
                Unit = getEnumValue(Convert.ToInt32(product.Unit)),
                Description = product.Description,
                ModifiedDate = product.ModifiedDate.GetValueOrDefault().ToString("dd/MM/yyyy"),
                ChildProducts = GetChildProducts(product.Id)
            }).ToList();

            return(Json(new { data = productList }, JsonRequestBehavior.AllowGet));
            ///return View(productList,JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 20
0
        public List <SelectListItem> SupplierDD()
        {
            List <SelectListItem> list = new List <SelectListItem>();

            try
            {
                using (var db = new ArityEntities())
                {
                    var data = (from a in db.Users
                                join b in db.UserTypes on a.Id equals b.UserId
                                where b.Id == 4
                                select new SelectListItem
                    {
                        Text = a.UserName,
                        Value = a.Id.ToString()
                    });
                }
                return(list);
            }
            catch (Exception ex)
            { throw; }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Order details
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult OrderDetail(int id)
        {
            ArityEntities objDb = new ArityEntities();

            return(View(objDb.Orders.Where(_ => _.Id == id).FirstOrDefault()));
        }
Exemplo n.º 22
0
 public UserController()
 {
     dataContext = new ArityEntities();
 }