Exemplo n.º 1
0
        public ActionResult CreateUpdateItem(ItemSingleModel model)
        {
            var status = itemService.GetItemStatus();

            ViewBag.Statuses = new SelectList(status, "Status", "Status");
            if (ModelState.IsValid)
            {
                if (model.Id > 0)
                {
                    if (custService.CheckExistingCustomer(model.CustomerPhonenumber))
                    {
                        var item = itemService.Update(model);
                        return(RedirectToAction("CustomerDetail", "Admin", new { customerId = model.CustomerId }));
                    }
                    else
                    {
                        ViewBag.Message = "ເບີໂທດັ່ງກ່າວຍັງບໍ່ທັນໄດ້ລົງທະບຽນ";
                        return(View());
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(model.CustomerPhonenumber))
                    {
                        if (custService.CheckExistingCustomer(model.CustomerPhonenumber))
                        {
                            model.CustomerId = 0;
                            var item = itemService.CreateItemForDelivery(model);
                            return(View());
                        }
                        else
                        {
                            ViewBag.Message = "ເບີໂທດັ່ງກ່າວຍັງບໍ່ທັນໄດ້ລົງທະບຽນ";
                            return(View());
                        }
                    }
                    else if (model.CustomerId > 0)
                    {
                        if (custService.CheckExistingCustomer(model.CustomerId))
                        {
                            var item = itemService.CreateItemForDelivery(model);
                            return(View());
                        }
                        else
                        {
                            ViewBag.Message = "ເບີໂທດັ່ງກ່າວຍັງບໍ່ທັນໄດ້ລົງທະບຽນ";
                            return(View());
                        }
                    }
                    else
                    {
                        return(View());
                    }
                }
            }
            else
            {
                return(View());
            }
        }
Exemplo n.º 2
0
 public bool Update(ItemSingleModel model)
 {
     using (var db = new EntityContext())
     {
         var items = itemsUtility.GetItemById(model.Id ?? default(int), db);
         if (items == null)
         {
             return(false);
         }
         ;
         db.Entry(items).State  = EntityState.Modified;
         items.ItemName         = model.ItemName;
         items.Customer         = db.tbCustomers.FirstOrDefault(x => x.Id == model.CustomerId);
         items.ItemValue_Baht   = model.ItemValue_Baht;
         items.ItemValue_Dollar = model.ItemValue_Dollar;
         items.ItemValue_Kip    = model.ItemValue_Kip;
         items.ReceipverPhone   = model.ReceipverPhone;
         items.ReceiverAddress  = model.ReceiverAddress;
         items.ReceiverName     = model.ReceiverName;
         items.Descripttion     = model.Description;
         if (model.Status != null)
         {
             items.Status = db.tbItemStatuses.FirstOrDefault(s => s.Status == model.Status);
         }
         db.SaveChanges();
         return(true);
     }
 }
Exemplo n.º 3
0
 public ItemSingleModel GetSingle(int id)
 {
     using (var db = new EntityContext())
     {
         var items = itemsUtility.GetItemById(id, db);
         if (items == null)
         {
             return(null);
         }
         var model = new ItemSingleModel
         {
             Id                  = items.Id,
             ItemName            = items.ItemName,
             Status              = items.Status.Status,
             CustomerId          = items.Customer.Id,
             CustomerPhonenumber = items.Customer.Phonenumber,
             Description         = items.Descripttion,
             isDeleted           = items.isDeleted,
             ItemValue_Baht      = items.ItemValue_Baht,
             ItemValue_Dollar    = items.ItemValue_Dollar,
             ItemValue_Kip       = items.ItemValue_Kip,
             ReceipverPhone      = items.ReceipverPhone,
             ReceiverAddress     = items.ReceiverAddress,
             ReceiverName        = items.ReceiverName,
             TrackingNumber      = items.TrackingNumber,
             ReceiveDate         = items.ReceiveDate?.ToString("dd-MM-yyyy"),
             SendingDate         = items.SendingDate?.ToString("dd-MM-yyyy"),
             ConfrimDate         = items.ConfrimDate?.ToString("dd-MM-yyyy"),
             CreatedDate         = items.CreatedDate?.ToString("dd-MM-yyyy")
         };
         return(model);
     }
 }
Exemplo n.º 4
0
        private TbItems CreateItemMethod(ItemSingleModel model, EntityContext db, DbContextTransaction dbtransact, int itemstatus)
        {
            TbItems item = new TbItems
            {
                ItemName         = model.ItemName,
                ItemValue_Baht   = model.ItemValue_Baht,
                ItemValue_Dollar = model.ItemValue_Dollar,
                ItemValue_Kip    = model.ItemValue_Kip,
                isDeleted        = false,
                Status           = db.tbItemStatuses.FirstOrDefault(s => s.Id == itemstatus),
                Customer         = customerUtility.GetCustomerById(db, model.CustomerId),
                CreatedDate      = DateTime.Now,
                ReceipverPhone   = model.ReceipverPhone,
                ReceiverAddress  = model.ReceiverAddress,
                ReceiverName     = model.ReceiverName,
                Descripttion     = model.Description
            };

            db.TbItems.Add(item);
            db.SaveChanges();
            db.Entry(item).State = EntityState.Modified;
            string        customerId = model.CustomerId.ToString().PadLeft(4, '0');
            string        itemId     = item.Id.ToString().PadLeft(7, '0');
            StringBuilder sb         = new StringBuilder();

            sb.Append("U" + customerId);
            sb.Append("I" + itemId);
            item.TrackingNumber = sb.ToString();
            db.SaveChanges();
            dbtransact.Commit();
            return(item);
        }
Exemplo n.º 5
0
        public bool UpdateExistingItem(UpdateItemModel item)
        {
            Item editItem = new Item();
            ItemDetailMapping singleDetail = new ItemDetailMapping();
            ItemSingleModel   result       = new ItemSingleModel();
            bool updateDetailMapping       = false;

            var brandName  = _itemDataAccess.GetBrandByName(item.BrandName);
            var codeDetail = _itemDataAccess.GetAllItemStatus();

            editItem.Id                  = item.Id;
            editItem.ItemName            = item.ItemName;
            editItem.CategoryID          = item.CategoryId;
            editItem.SubCategoryID       = item.SubCategoryId;
            editItem.LocationID          = item.LocationId;
            editItem.BrandID             = brandName.Id;
            editItem.Quantity            = item.Quantity;
            editItem.MeasuredBy          = item.MeasuredBy;
            editItem.ThresholdQty        = item.ThresholdQty;
            editItem.WarningThresholdQty = item.WarningThresholdQty;
            editItem.Notes               = item.Notes;
            editItem.Sku                 = item.Sku;
            editItem.UpdateUserName      = "******";
            editItem.UpdateDttm          = DateTime.UtcNow;
            editItem.UnitPrice           = (decimal)item.UnitPrice;
            editItem.RetailPrice         = (decimal)item.RetailPrice;

            for (int i = 0; i < item.ItemDetail.Count; i++)
            {
                singleDetail.Id              = item.ItemDetail[i].Id;
                singleDetail.ItemID          = item.Id;
                singleDetail.ItemDetailID    = item.ItemDetail[i].ItemDetailId;
                singleDetail.ItemDetailValue = item.ItemDetail[i].ItemDetailValue;
                singleDetail.IsActive        = true;
                singleDetail.UpdateUserName  = "******";
                singleDetail.UpdateDttm      = DateTime.Now;

                updateDetailMapping = _itemDataAccess.UpdateItemDetailMappingByItemId(singleDetail);
                if (!updateDetailMapping)
                {
                    break;
                }
            }

            var updateItem = _itemDataAccess.UpdateItemById(editItem);


            if (updateItem && updateDetailMapping)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 6
0
 public ItemSingleModel CreateItemById(ItemSingleModel model)
 {
     using (var db = new EntityContext())
     {
         using (var dbtransact = db.Database.BeginTransaction())
         {
             int     itemstatus = 3;
             TbItems item       = CreateItemMethod(model, db, dbtransact, itemstatus);
             return(GetSingle(item.Id));
         }
     }
 }
Exemplo n.º 7
0
 public bool Create(ItemSingleModel model)
 {
     using (var db = new EntityContext())
     {
         using (var dbtransact = db.Database.BeginTransaction())
         {
             int     itemstatus = 1;
             TbItems item       = CreateItemMethod(model, db, dbtransact, itemstatus);
             return(true);
         }
     }
 }
Exemplo n.º 8
0
        public ActionResult CreateUpdateItem(ItemSingleModel model)
        {
            if (Session["UserId"] != null)
            {
                if (ModelState.IsValid)
                {
                    model.Status = "ຢູ່ຮ້ານ";
                    int userId = (int)Session["UserId"];
                    model.CustomerId = userId;
                    if (model.Id > 0)
                    {
                        bool result = _itemServ.Update(model);
                        if (result == true)
                        {
                            ViewBag.Message = "ປ່ຽນແປງຂໍ້ມູນສີນຄ້າສຳເລັດ";
                            int id        = model.Id ?? default(int);
                            var postModel = _itemServ.GetSingle(id);
                            return(View(postModel));
                        }
                        else
                        {
                            ViewBag.Message = "ປ່ຽນແປງຂໍ້ມູນສີນຄ້າບໍ່ສຳເລັດ";

                            return(View(model));
                        }
                    }
                    else
                    {
                        bool result = _itemServ.Create(model);
                        if (result == true)
                        {
                            ViewBag.Message = "ເພີ່ມລາຍການສຳເລັດ";
                            ModelState.Clear();
                            return(View(new ItemSingleModel()));
                        }
                        else
                        {
                            ViewBag.Message = "ເພີ່ມລາຍການບໍ່ສຳເລັດ";
                            return(View(model));
                        }
                    }
                }
                else
                {
                    return(View());
                }
            }
            else
            {
                return(RedirectToAction("CLogin", "Account"));
            }
        }
Exemplo n.º 9
0
        public ItemSingleModel GetItemById(int id)
        {
            ItemSingleModel        result             = new ItemSingleModel();
            ItemDetailModel        singleItemDetail   = new ItemDetailModel();
            List <ItemDetailModel> completeItemDetail = new List <ItemDetailModel>();

            var query           = _itemDataAccess.GetItemById(id);
            var itemDetailQuery = _itemDataAccess.GetItemDetailByItemId(query.Id);
            var uom             = _itemDataAccess.GetItemUnitsOfMeasure(itemDetailQuery);

            result.Id                  = query.Id;
            result.ItemName            = query.ItemName;
            result.CategoryId          = query.CategoryID;
            result.SubCategoryId       = query.SubCategoryID;
            result.BrandName           = query.Brand.BrandName;
            result.LocationId          = query.LocationID;
            result.Quantity            = query.Quantity.HasValue ? query.Quantity.Value : 0;
            result.ThresholdQty        = query.ThresholdQty.HasValue ? query.ThresholdQty.Value : 0;
            result.WarningThresholdQty = query.WarningThresholdQty.HasValue ? query.WarningThresholdQty.Value : 0;
            result.MeasuredBy          = query.MeasuredBy;
            result.Sku                 = query.Sku;
            result.Notes               = query.Notes;
            result.StatusCd            = query.CodeDetail.CodeValue;
            result.CreateUserName      = query.CreateUserName;
            result.CreateDttm          = query.CreateDttm;
            result.UpdateUserName      = query.UpdateUserName;
            result.UpdateDttm          = query.UpdateDttm;
            result.UnitPrice           = query.UnitPrice.HasValue ? query.UnitPrice.Value : 0.00m;
            result.RetailPrice         = query.RetailPrice.HasValue ? query.RetailPrice.Value : 0.00m;

            for (int i = 0; i < itemDetailQuery.Count; i++)
            {
                singleItemDetail.Id                 = itemDetailQuery[i].Id;
                singleItemDetail.ItemDetailId       = itemDetailQuery[i].ItemDetail.Id;
                singleItemDetail.ShowUnitsOfMeasure = itemDetailQuery[i].ItemDetail.ShowUnitsOfMeasure;
                singleItemDetail.ItemDetailName     = itemDetailQuery[i].ItemDetail.ItemDetailName;
                singleItemDetail.ItemDetailValue    = itemDetailQuery[i].ItemDetailValue;
                singleItemDetail.UnitOfMeasure      = uom.Where(x => x.Id == itemDetailQuery[i].ItemDetail.UnitsOfMeasureID)
                                                      .Select(x => x.UnitOfMeasure).FirstOrDefault();

                completeItemDetail.Add(singleItemDetail);
                singleItemDetail = new ItemDetailModel();
            }

            result.ItemDetail = completeItemDetail;

            return(result);
        }
Exemplo n.º 10
0
 public bool AddDescription(ItemSingleModel model)
 {
     using (var db = new EntityContext())
     {
         if (model.Id > 0)
         {
             var item = itemsUtility.GetItemById(model.Id ?? default(int), db);
             db.Entry(item).State = EntityState.Modified;
             item.Descripttion    = model.Description;
             db.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 11
0
        public List <ItemSingleModel> GetOldestStocks()
        {
            List <ItemSingleModel> result     = new List <ItemSingleModel>();
            ItemSingleModel        singleItem = new ItemSingleModel();

            var items = _itemDataAccess.GetOldestStocks();


            for (int i = 0; i < items.Count; i++)
            {
                singleItem.Id       = items[i].Id;
                singleItem.ItemName = items[i].ItemName;

                result.Add(singleItem);
                singleItem = new ItemSingleModel();
            }

            return(result);
        }
Exemplo n.º 12
0
 public ActionResult CreateItem(ItemSingleModel model)
 {
     if (ModelState.IsValid)
     {
         if (custService.CheckExistingCustomer(model.CustomerPhonenumber))
         {
             var item = itemService.CreateItemForDelivery(model);
             return(RedirectToAction("ShowItem", "Delivery", new { id = item.Id }));
         }
         else
         {
             ViewBag.Message = "ເບີໂທດັ່ງກ່າວຍັງບໍ່ທັນໄດ້ລົງທະບຽນ";
             return(View());
         }
     }
     else
     {
         return(View());
     }
 }
Exemplo n.º 13
0
 public ItemSingleModel CreateItemForDelivery(ItemSingleModel model)
 {
     using (var db = new EntityContext())
     {
         using (var dbtransact = db.Database.BeginTransaction())
         {
             int itemstatus = 3;
             if (model.Status != null)
             {
                 itemstatus = db.tbItemStatuses.FirstOrDefault(x => x.Status == model.Status).Id;
             }
             if (model.CustomerId == 0)
             {
                 model.CustomerId = db.tbCustomers.FirstOrDefault(x => x.Phonenumber == model.CustomerPhonenumber).Id;
             }
             TbItems item = CreateItemMethod(model, db, dbtransact, itemstatus);
             return(GetSingle(item.Id));
         }
     }
 }
Exemplo n.º 14
0
 public ActionResult CreateUpdateItem(ItemSingleModel model)
 {
     return(View());
 }
Exemplo n.º 15
0
        public ActionResult AddDescription(ItemSingleModel model)
        {
            bool result = itemService.AddDescription(model);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 16
0
        public ItemSingleModel InsertNewItem(InsertItemModel item)
        {
            Item newItem = new Item();
            List <ItemDetailMapping> detail       = new List <ItemDetailMapping>();
            ItemDetailMapping        singleDetail = new ItemDetailMapping();
            ItemSingleModel          result       = new ItemSingleModel();

            var brandName  = _itemDataAccess.GetBrandByName(item.BrandName);
            var codeDetail = _itemDataAccess.GetAllItemStatus();

            newItem.ItemName            = item.ItemName;
            newItem.CategoryID          = item.CategoryId;
            newItem.SubCategoryID       = item.SubCategoryId;
            newItem.StatusCd            = codeDetail.Where(x => x.CodeValue.Equals("Active")).Select(x => x.Id).FirstOrDefault();
            newItem.LocationID          = item.LocationId;
            newItem.BrandID             = brandName.Id;
            newItem.Quantity            = item.Quantity;
            newItem.MeasuredBy          = item.MeasuredBy;
            newItem.ThresholdQty        = item.ThresholdQty;
            newItem.WarningThresholdQty = item.WarningThresholdQty;
            newItem.Notes          = item.Notes;
            newItem.Sku            = item.Sku;
            newItem.CreateUserName = "******";
            newItem.CreateDttm     = DateTime.UtcNow;
            newItem.UpdateUserName = "******";
            newItem.UpdateDttm     = DateTime.UtcNow;

            var insertedItem = _itemDataAccess.InsertNewItem(newItem);

            if (insertedItem != null)
            {
                for (int i = 0; i < item.ItemDetail.Count; i++)
                {
                    singleDetail.ItemDetailID    = item.ItemDetail[i].ItemDetailId;
                    singleDetail.ItemDetailValue = item.ItemDetail[i].ItemDetailValue;
                    singleDetail.ItemID          = insertedItem.Id;
                    singleDetail.IsActive        = true;
                    singleDetail.CreateUserName  = "******";
                    singleDetail.CreateDttm      = DateTime.UtcNow;
                    singleDetail.UpdateUserName  = "******";
                    singleDetail.UpdateDttm      = DateTime.Now;

                    detail.Add(singleDetail);

                    singleDetail = new ItemDetailMapping();
                }

                var insertedDetail = _itemDataAccess.InsertNewItemDetailMapping(detail);

                result.Id                  = insertedItem.Id;
                result.ItemName            = insertedItem.ItemName;
                result.CategoryId          = insertedItem.CategoryID;
                result.SubCategoryId       = insertedItem.SubCategoryID;
                result.BrandName           = item.BrandName;
                result.LocationId          = insertedItem.LocationID;
                result.Quantity            = insertedItem.Quantity.HasValue ? insertedItem.Quantity.Value : 0;
                result.ThresholdQty        = insertedItem.ThresholdQty.HasValue ? insertedItem.ThresholdQty.Value : 0;
                result.WarningThresholdQty = insertedItem.WarningThresholdQty.HasValue ? insertedItem.WarningThresholdQty.Value : 0;
                result.MeasuredBy          = insertedItem.MeasuredBy;
                result.Sku                 = insertedItem.Sku;
                result.Notes               = insertedItem.Notes;
                result.StatusCd            = codeDetail.Where(x => x.Id == insertedItem.StatusCd).Select(x => x.CodeValue).FirstOrDefault();
                result.CreateUserName      = insertedItem.CreateUserName;
                result.CreateDttm          = insertedItem.CreateDttm;
                result.UpdateUserName      = insertedItem.UpdateUserName;
                result.UpdateDttm          = insertedItem.UpdateDttm;

                if (insertedDetail)
                {
                    return(result);
                }
            }
            return(new ItemSingleModel());
        }