private static MiscellaneousTransaction GetEntityByModel(MiscellaneousTransactionDetailModel model, int count)
        {
            if (model == null) return null;

            MiscellaneousTransaction entity = new MiscellaneousTransaction();

            if (count == 0)
            {
                entity.CompanyId = AuthenticationHelper.CompanyId.Value;
                entity.CreateBy = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
            }
            else
            {
                entity.CompanyId = model.CompanyId;
                entity.CreateBy = model.CreateBy;
                entity.CreateDate = model.CreateDate;
            }

            entity.CodeCombinationId = model.CodeCombinationId;
            entity.Cost = model.Cost;
            entity.Id = model.Id;
            entity.ItemId = model.ItemId;
            entity.LocatorId = model.LocatorId;
            entity.LotNo = model.LotNo;
            entity.Quantity = model.Quantity;
            entity.SerialNo = model.SerialNo;
            entity.SOBId = model.SOBId;
            entity.TransactionDate = model.TransactionDate;
            entity.TransactionType = model.TransactionType;
            entity.UpdateBy = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;
            entity.WarehouseId = model.WarehouseId;
            return entity;
        }
        private static LotNumber GetLotEntityByMiscellaneousTransaction(MiscellaneousTransactionDetailModel model, int count)
        {
            if (model == null) return null;

            LotNumber entity = new LotNumber();
            if (count == 0)
            {
                entity.CreateBy = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
            }
            else
            {
                entity.CreateBy = model.CreateBy;
                entity.CreateDate = model.CreateDate;
            }

            entity.CompanyId = AuthenticationHelper.CompanyId.Value;
            entity.Id = model.Id;
            entity.ItemId = model.ItemId;
            entity.LotNo = model.LotNo;
            entity.SOBId = SessionHelper.SOBId;
            entity.SourceId = model.Id;
            entity.SourceType = "Miscellaneous Transaction";
            entity.UpdateBy = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;
            return entity;
        }
 public ActionResult DeletePartial(MiscellaneousTransactionDetailModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             model.SOBId = SessionHelper.SOBId;
             MiscellaneousTransactionModel MiscellaneousTransaction = SessionHelper.MiscellaneousTransaction;
             MiscellaneousTransactionHelper.DeleteMiscellaneousTransactionDetail(model);
             SessionHelper.MiscellaneousTransaction = MiscellaneousTransaction;
             IList<MiscellaneousTransactionDetailModel> MiscellaneousTransactionDetail = MiscellaneousTransactionHelper.GetMiscellaneousTransactionDetail(model.SOBId, model.TransactionType, model.CodeCombinationId, model.TransactionDate);
             return PartialView("createPartial", MiscellaneousTransactionDetail);
         }
         catch (Exception e)
         {
             ViewData["EditError"] = e.Message;
         }
     }
     else
         ViewData["EditError"] = "Please, correct all errors.";
     return PartialView("createPartial");
 }
 public ActionResult UpdatePartial(MiscellaneousTransactionDetailModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             model.SOBId = SessionHelper.SOBId;
             if (SessionHelper.MiscellaneousTransaction != null)
             {
                 if (SessionHelper.MiscellaneousTransaction.MiscellaneousTransactionDetail.Any(rec => rec.LotNo == model.LotNo && rec.ItemId == model.ItemId))
                 {
                     ViewData["EditError"] = "Lot Number must be unique";
                     return PartialView("createPartial", MiscellaneousTransactionHelper.GetMiscellaneousTransactionDetail(model.SOBId, model.TransactionType, model.CodeCombinationId, model.TransactionDate));
                 }
                 if (SessionHelper.MiscellaneousTransaction.MiscellaneousTransactionDetail.Any(rec => rec.LotNo == model.LotNo && rec.SerialNo == model.SerialNo))
                 {
                     ViewData["EditError"] = "Serial Number must be unique";
                     return PartialView("createPartial", MiscellaneousTransactionHelper.GetMiscellaneousTransactionDetail(model.SOBId, model.TransactionType, model.CodeCombinationId, model.TransactionDate));
                 }
             }
             if (LotNumberHelper.CheckLotNumAvailability(model.LotNo, model.ItemId, SessionHelper.SOBId).Any())
             {
                 ViewData["EditError"] = "Lot Number must be unique";
                 return PartialView("createPartial", MiscellaneousTransactionHelper.GetMiscellaneousTransactionDetail(model.SOBId, model.TransactionType, model.CodeCombinationId, model.TransactionDate));
             }
             //if (LotNumberHelper.CheckSerialNumAvailability(model.LotNo, model.SerialNo).Any())
             //{
             //    ViewData["EditError"] = "Serial Number must be unique";
             //    return PartialView("createPartial", MiscellaneousTransactionHelper.GetMiscellaneousTransactionDetail(model.SOBId, model.TransactionType, model.CodeCombinationId, model.TransactionDate));
             //}
             MiscellaneousTransactionHelper.UpdateMiscellaneousTransactionDetail(model);
         }
         catch (Exception e)
         {
             ViewData["EditError"] = e.Message;
         }
     }
     else
         ViewData["EditError"] = "Please, correct all errors.";
     return PartialView("createPartial", MiscellaneousTransactionHelper.GetMiscellaneousTransactionDetail(model.SOBId, model.TransactionType, model.CodeCombinationId, model.TransactionDate));
 }
 public static void DeleteMiscellaneousTransactionDetail(MiscellaneousTransactionDetailModel model)
 {
     MiscellaneousTransactionModel miscellaneousTransaction = SessionHelper.MiscellaneousTransaction;
     MiscellaneousTransactionDetailModel miscellaneousTransactionDetail = miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id);
     miscellaneousTransaction.MiscellaneousTransactionDetail.Remove(miscellaneousTransactionDetail);
 }
        public static void UpdateMiscellaneousTransactionDetail(MiscellaneousTransactionDetailModel model)
        {
            MiscellaneousTransactionModel miscellaneousTransaction = SessionHelper.MiscellaneousTransaction;

            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).CodeCombinationId = model.CodeCombinationId;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).CompanyId = model.CompanyId;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).Cost = model.Cost;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).Id = model.Id;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).ItemId = model.ItemId;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).LocatorId = model.LocatorId;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).LotNo = model.LotNo;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).Quantity = model.Quantity;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).SerialNo = model.SerialNo;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).SOBId = model.SOBId;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).TransactionDate = model.TransactionDate;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).TransactionType = model.TransactionType;
            miscellaneousTransaction.MiscellaneousTransactionDetail.FirstOrDefault(x => x.Id == model.Id).WarehouseId = model.WarehouseId;
        }
 public static void InsertMiscellaneousTransactionDetail(MiscellaneousTransactionDetailModel model)
 {
     MiscellaneousTransactionModel moveOrder = SessionHelper.MiscellaneousTransaction;
     moveOrder.MiscellaneousTransactionDetail.Add(model);
 }
 public static string InsertSerialNumber(MiscellaneousTransactionDetailModel entity)
 {
     return service.InsertSerialNum(GetSerialEntityByMiscellaneousTransaction(entity, 0));
 }
 public static string Insert(MiscellaneousTransactionDetailModel entity)
 {
     return service.Insert(GetLotEntityByMiscellaneousTransaction(entity, 0));
 }
        private static SerialNumber GetSerialEntityByMiscellaneousTransaction(MiscellaneousTransactionDetailModel model, int count)
        {
            if (model == null) return null;

            SerialNumber entity = new SerialNumber();
            if (count == 0)
            {
                entity.CreateBy = AuthenticationHelper.UserId;
                entity.CreateDate = DateTime.Now;
            }
            else
            {
                entity.CreateBy = model.CreateBy;
                entity.CreateDate = model.CreateDate;
            }

            entity.Id = model.Id;
            entity.LotNo = model.LotNo;
            entity.SerialNo = model.SerialNo;
            entity.UpdateBy = AuthenticationHelper.UserId;
            entity.UpdateDate = DateTime.Now;
            return entity;
        }