public IHttpActionResult GetVoucherDTLById(int id)
        {
            VoucherDTLViewModel voucherDTL = null;

            using (var ctx = new dbInventoryEntities())
            {
                voucherDTL = ctx.tblVoucherDTLs
                             .Where(s => s.intId == id)
                             .Select(s => new VoucherDTLViewModel()
                {
                    intVNo          = s.intVNo,
                    intId           = s.intId,
                    intCategory     = s.intCategory,
                    intItemCode     = s.intItemCode,
                    intPieces       = s.intPieces,
                    floatRate       = s.floatRate,
                    floatCommission = s.floatCommission,
                    floatAmount     = s.floatAmount
                }).FirstOrDefault <VoucherDTLViewModel>();
            }

            if (voucherDTL == null)
            {
                return(NotFound());
            }

            return(Ok(voucherDTL));
        }
        public IHttpActionResult DeleteVoucher(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Not a valid Voucher ID"));
            }

            using (var ctx = new dbInventoryEntities())
            {
                var voucher = ctx.tblVouchers
                              .Where(s => s.intVoucherNo == id)
                              .FirstOrDefault();
                ctx.Entry(voucher).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();

                var voucherDTL = ctx.tblVoucherDTLs
                                 .Where(s => s.intVNo == id)
                                 .ToList();
                ctx.tblVoucherDTLs.RemoveRange(voucherDTL);
                //foreach (var item in voucherDTL)
                //{
                //    ctx.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                //    ctx.SaveChanges();
                //}
            }

            return(Ok());
        }
        public IHttpActionResult GetAllVouchersDTL()
        {
            IList <VoucherDTLViewModel> voucherDTL = null;

            using (var ctx = new dbInventoryEntities())
            {
                voucherDTL = ctx.tblVoucherDTLs
                             .Select(s => new VoucherDTLViewModel()
                {
                    intVNo          = s.intVNo,
                    intId           = s.intId,
                    intCategory     = s.intCategory,
                    intItemCode     = s.intItemCode,
                    intPieces       = s.intPieces,
                    floatRate       = s.floatRate,
                    floatCommission = s.floatCommission,
                    floatAmount     = s.floatAmount
                }).ToList <VoucherDTLViewModel>();
            }

            if (voucherDTL.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(voucherDTL));
        }
        public IHttpActionResult GetVoucherById(int id)
        {
            using (var ctx = new dbInventoryEntities())
            {
                List <ResultVM> resList = new List <ResultVM>();

                resList = (from vc in ctx.tblVouchers
                           join vcd in ctx.tblVoucherDTLs on vc.intVoucherNo equals vcd.intVNo
                           where vc.intVoucherNo == id
                           select new ResultVM
                {
                    intId = vcd.intId,
                    intVoucherNo = vc.intVoucherNo,
                    dtDate = vc.dtDate,
                    intZoneName = vc.intZoneName,
                    intSOName = vc.intSOName,
                    intCategory = vcd.intCategory,
                    intItemCode = vcd.intItemCode,
                    intPieces = vcd.intPieces,
                    floatRate = vcd.floatRate,
                    floatCommission = vcd.floatCommission,
                    floatAmount = vcd.floatAmount
                }).OrderByDescending(x => x.intVoucherNo).ToList();

                return(Ok(resList));
            }
        }
        public IHttpActionResult PostNewVoucherDTL(VoucherDTLViewModel voucherDTL)
        {
            //if (!ModelState.IsValid)
            //    return BadRequest("Invalid data.");

            using (var ctx = new dbInventoryEntities())
            {
                int _intId = 1;
                var obj    = ctx.tblVoucherDTLs.OrderByDescending(t => t.intId).FirstOrDefault();
                if (obj != null)
                {
                    _intId = obj.intId + 1;
                }

                ctx.tblVoucherDTLs.Add(new tblVoucherDTL()
                {
                    intVNo          = voucherDTL.intVNo,
                    intId           = _intId,
                    intCategory     = voucherDTL.intCategory,
                    intItemCode     = voucherDTL.intItemCode,
                    intPieces       = voucherDTL.intPieces,
                    floatRate       = voucherDTL.floatRate,
                    floatCommission = voucherDTL.floatCommission,
                    floatAmount     = voucherDTL.floatCommission
                });
                try
                {
                    ctx.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }

            return(Ok());
        }
        public IHttpActionResult Put(VoucherDTLViewModel voucherDTL)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            using (var ctx = new dbInventoryEntities())
            {
                try
                {
                    var existingVoucherDTL = ctx.tblVoucherDTLs.Where(s => s.intId == voucherDTL.intId)
                                             .FirstOrDefault <tblVoucherDTL>();

                    if (existingVoucherDTL != null)
                    {
                        existingVoucherDTL.intCategory     = voucherDTL.intCategory;
                        existingVoucherDTL.intItemCode     = voucherDTL.intItemCode;
                        existingVoucherDTL.intPieces       = voucherDTL.intPieces;
                        existingVoucherDTL.floatRate       = voucherDTL.floatRate;
                        existingVoucherDTL.floatCommission = voucherDTL.floatCommission;
                        existingVoucherDTL.floatAmount     = voucherDTL.floatAmount;


                        ctx.SaveChanges();
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }

            return(Ok());
        }
Beispiel #7
0
        // GET api/<controller>/5
        public IHttpActionResult GetItemById(int id)
        {
            ItemViewModel item = null;

            using (var ctx = new dbInventoryEntities())
            {
                item = ctx.tblItems
                       .Where(s => s.intCode == id)
                       .Select(s => new ItemViewModel()
                {
                    intCode               = s.intCode,
                    barCode               = s.barCode,
                    varName               = s.varName,
                    varShortName          = s.varShortName,
                    intClass              = s.intCategory,
                    intCostMethod         = s.intCostMethod,
                    intSupplier           = s.intSupplier,
                    intPacking            = s.intPacking,
                    intPackingQuantity    = s.intPackingQuantity,
                    intPackingType        = s.intPackingType,
                    varMinOrderLevel      = s.varMinOrderLevel,
                    varMaxOrderLevel      = s.varMaxOrderLevel,
                    varDescription        = s.varDescription,
                    varOrderLevel         = s.varOrderLevel,
                    intOrderLevelQuantity = s.intOrderLevelQuantity,
                    varLocation           = s.varLocation,
                    intWeight             = s.intWeight,
                    intWeightUnit         = s.intWeightUnit,
                    intCategory           = s.intCategory,
                    intRegNum             = s.intRegNum,
                    varManuBy             = s.varManuBy,
                    varPacking            = s.varPacking,
                    Image        = s.Image,
                    bitPV        = s.bitPV,
                    bitSV        = s.bitSV,
                    bitDC        = s.bitDC,
                    bitGRN       = s.bitGRN,
                    bitStockable = s.bitStockable
                }).FirstOrDefault <ItemViewModel>();
            }

            if (item == null)
            {
                return(NotFound());
            }

            return(Ok(item));
        }
        public IHttpActionResult DeleteVoucherDTL(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Not a valid VoucherDTL ID"));
            }

            using (var ctx = new dbInventoryEntities())
            {
                var voucherDTL = ctx.tblVoucherDTLs
                                 .Where(s => s.intId == id)
                                 .FirstOrDefault();
                ctx.Entry(voucherDTL).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }

            return(Ok());
        }
 public int VoucherId()
 {
     //var obj;
     using (var ctx = new dbInventoryEntities())
     {
         var obj = ctx.tblVouchers.Max(t => t.intVoucherNo);
         if (obj == 0)
         {
             return(obj);
         }
         //int id = Convert.ToInt32(obj);
         //return Ok(obj);
         else
         {
             return(obj + 1);
         }
     }
 }
Beispiel #10
0
        // DELETE api/<controller>/5
        public IHttpActionResult DeleteItem(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Not a valid Item ID"));
            }

            using (var ctx = new dbInventoryEntities())
            {
                var item = ctx.tblItems
                           .Where(s => s.intCode == id)
                           .FirstOrDefault();
                ctx.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                ctx.SaveChanges();
            }

            return(Ok());
        }
        public IHttpActionResult DeleteVoucherDTLArr(int id)
        {
            if (id <= 0)
            {
                return(BadRequest("Not a valid Voucher ID"));
            }

            using (var ctx = new dbInventoryEntities())
            {
                var voucherDTL = ctx.tblVoucherDTLs
                                 .Where(s => s.intVNo == id)
                                 .ToList();
                foreach (var item in voucherDTL)
                {
                    ctx.Entry(item).State = System.Data.Entity.EntityState.Deleted;
                    ctx.SaveChanges();
                }
            }

            return(Ok());
        }
        public IHttpActionResult GetAllVouchers()
        {
            IList <VoucherViewModel> voucher = null;

            using (var ctx = new dbInventoryEntities())
            {
                voucher = ctx.tblVouchers
                          .Select(s => new VoucherViewModel()
                {
                    intVoucherNo = s.intVoucherNo,
                    dtDate       = s.dtDate,
                    intZoneName  = s.intZoneName,
                    intSOName    = s.intSOName
                }).ToList <VoucherViewModel>();
            }

            if (voucher.Count == 0)
            {
                return(NotFound());
            }

            return(Ok(voucher));
        }
        public IHttpActionResult Put(VoucherViewModel voucher)
        {
            //if (!ModelState.IsValid)
            //    return BadRequest("Not a valid model");

            using (var ctx = new dbInventoryEntities())
            {
                try
                {
                    var existingVoucher = ctx.tblVouchers.Where(s => s.intVoucherNo == voucher.intVoucherNo)
                                          .FirstOrDefault <tblVoucher>();

                    if (existingVoucher != null)
                    {
                        //existingVoucher.dtDate = voucher.dtDate;
                        existingVoucher.intZoneName = voucher.intZoneName;
                        existingVoucher.intSOName   = voucher.intSOName;

                        ctx.SaveChanges();
                    }

                    int id = 0;
                    foreach (var detail in voucher.voucherDTL)
                    {
                        int id1 = voucher.voucherDTL[id].intId;
                        var existingVoucherDTL = ctx.tblVoucherDTLs.Where(s => s.intId == id1)
                                                 .FirstOrDefault <tblVoucherDTL>();
                        if (existingVoucherDTL != null)
                        {
                            existingVoucherDTL.intCategory     = detail.intCategory;
                            existingVoucherDTL.intItemCode     = detail.intItemCode;
                            existingVoucherDTL.intPieces       = detail.intPieces;
                            existingVoucherDTL.floatRate       = detail.floatRate;
                            existingVoucherDTL.floatCommission = detail.floatCommission;
                            existingVoucherDTL.floatAmount     = detail.floatAmount;

                            ctx.SaveChanges();
                        }
                        id++;
                    }

                    int _intId = 1;
                    var obj1   = ctx.tblVoucherDTLs.OrderByDescending(t => t.intId).FirstOrDefault();
                    if (obj1 != null)
                    {
                        _intId = obj1.intId + 1;
                    }
                    foreach (var detail1 in voucher.voucherDTL1)
                    {
                        var detailVoucher1 = new tblVoucherDTL
                        {
                            intId           = _intId,
                            intCategory     = detail1.intCategory,
                            intVNo          = voucher.intVoucherNo,
                            intItemCode     = detail1.intItemCode,
                            intPieces       = detail1.intPieces,
                            floatRate       = detail1.floatRate,
                            floatCommission = detail1.floatCommission,
                            floatAmount     = detail1.floatAmount
                        };
                        ctx.tblVoucherDTLs.Add(detailVoucher1);
                        _intId++;

                        ctx.SaveChanges();
                    }
                    //else
                    //{
                    //    return NotFound();
                    //}
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }

            return(Ok());
        }
Beispiel #14
0
        // PUT api/<controller>/5
        public IHttpActionResult Put(ItemViewModel item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid model"));
            }

            using (var ctx = new dbInventoryEntities())
            {
                try
                {
                    var existingItem = ctx.tblItems.Where(s => s.intCode == item.intCode)
                                       .FirstOrDefault <tblItem>();

                    if (existingItem != null)
                    {
                        existingItem.intCode               = item.intCode;
                        existingItem.barCode               = item.barCode;
                        existingItem.varName               = item.varName;
                        existingItem.varShortName          = item.varShortName;
                        existingItem.intClass              = item.intCategory;
                        existingItem.intCostMethod         = item.intCostMethod;
                        existingItem.intSupplier           = item.intSupplier;
                        existingItem.intPacking            = item.intPacking;
                        existingItem.intPackingQuantity    = item.intPackingQuantity;
                        existingItem.intPackingType        = item.intPackingType;
                        existingItem.varMinOrderLevel      = item.varMinOrderLevel;
                        existingItem.varMaxOrderLevel      = item.varMaxOrderLevel;
                        existingItem.varDescription        = item.varDescription;
                        existingItem.varOrderLevel         = item.varOrderLevel;
                        existingItem.intOrderLevelQuantity = item.intOrderLevelQuantity;
                        existingItem.varLocation           = item.varLocation;
                        existingItem.intWeight             = item.intWeight;
                        existingItem.intWeightUnit         = item.intWeightUnit;
                        existingItem.intCategory           = item.intCategory;
                        existingItem.intRegNum             = item.intRegNum;
                        existingItem.varManuBy             = item.varManuBy;
                        existingItem.varPacking            = item.varPacking;
                        existingItem.Image        = item.Image;
                        existingItem.bitPV        = item.bitPV;
                        existingItem.bitSV        = item.bitSV;
                        existingItem.bitDC        = item.bitDC;
                        existingItem.bitGRN       = item.bitGRN;
                        existingItem.bitStockable = item.bitStockable;

                        ctx.SaveChanges();
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
            }

            return(Ok());
        }
Beispiel #15
0
        // POST api/<controller>
        public IHttpActionResult PostNewItem(ItemViewModel item)
        {
            //if (!ModelState.IsValid)
            //    return BadRequest("Invalid data.");

            using (var ctx = new dbInventoryEntities())
            {
                int _intCode = 1;
                var obj      = ctx.tblItems.OrderByDescending(t => t.intCode).FirstOrDefault();
                if (obj != null)
                {
                    _intCode = obj.intCode + 1;
                }

                ctx.tblItems.Add(new tblItem()
                {
                    intCode               = item.intCode,
                    barCode               = item.barCode,
                    varName               = item.varName,
                    varShortName          = item.varShortName,
                    intClass              = item.intCategory,
                    intCostMethod         = item.intCostMethod,
                    intSupplier           = item.intSupplier,
                    intPacking            = item.intPacking,
                    intPackingQuantity    = item.intPackingQuantity,
                    intPackingType        = item.intPackingType,
                    varMinOrderLevel      = item.varMinOrderLevel,
                    varMaxOrderLevel      = item.varMaxOrderLevel,
                    varDescription        = item.varDescription,
                    varOrderLevel         = item.varOrderLevel,
                    intOrderLevelQuantity = item.intOrderLevelQuantity,
                    varLocation           = item.varLocation,
                    intWeight             = item.intWeight,
                    intWeightUnit         = item.intWeightUnit,
                    intCategory           = item.intCategory,
                    intRegNum             = item.intRegNum,
                    varManuBy             = item.varManuBy,
                    varPacking            = item.varPacking,
                    Image        = item.Image,
                    bitPV        = item.bitPV,
                    bitSV        = item.bitSV,
                    bitDC        = item.bitDC,
                    bitGRN       = item.bitGRN,
                    bitStockable = item.bitStockable
                });
                try
                {
                    ctx.SaveChanges();
                }
                catch (DbEntityValidationException ex)
                {
                    // Retrieve the error messages as a list of strings.
                    var errorMessages = ex.EntityValidationErrors
                                        .SelectMany(x => x.ValidationErrors)
                                        .Select(x => x.ErrorMessage);

                    // Join the list to a single string.
                    var fullErrorMessage = string.Join("; ", errorMessages);

                    // Combine the original exception message with the new one.
                    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

                    // Throw a new DbEntityValidationException with the improved exception message.
                    throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
                }
            }

            return(Ok());
        }