public SplitItemPTIViewModel(PreFligtManifest itemPti)
 {
     MyTitle         = "SPLIT ITEM PTI";
     SelectedItemPTI = itemPti;
     SourceView      = new ObservableCollection <PreFligtManifest>(new List <PreFligtManifest> {
         SelectedItemPTI
     });
     SaveCommand = new CommandHandler {
         CanExecuteAction = SaveValidate, ExecuteAction = SaveAction
     };
     CancelCommand = new CommandHandler {
         CanExecuteAction = x => true, ExecuteAction = x => WindowClose()
     };
 }
Example #2
0
        public collies SplitItemPTI(PreFligtManifest selectedItemPTI, int jumlah)
        {
            using (var db = new OcphDbContext())
            {
                var trans = db.BeginTransaction();
                try
                {
                    var sisa = selectedItemPTI.Pcs - jumlah;
                    if (!db.Collies.Update(O => new { O.Pcs }, new collies {
                        Pcs = jumlah
                    }, O => O.Id == selectedItemPTI.ColliesId))
                    {
                        throw new SystemException("Item PTI Tidak Berhasil Di Split");
                    }

                    var newItem = new collies {
                        Content = selectedItemPTI.Content, IsSended = false, Kemasan = selectedItemPTI.Kemasan, Pcs = sisa,
                        Price   = selectedItemPTI.Price, PtiId = selectedItemPTI.PTIId, Weight = selectedItemPTI.Weight
                    };
                    newItem.Id = db.Collies.InsertAndGetLastID(newItem);
                    if (newItem.Id <= 0)
                    {
                        throw new SystemException("Item PTI Tidak Berhasil Di Split");
                    }

                    var note = string.Format("Split PTI No {0:D6} item {1:D7} ({2}Colly) Menjadi {3} Colly dan {4}Colly", selectedItemPTI.PTIId,
                                             selectedItemPTI.ColliesId, selectedItemPTI.Pcs, sisa, jumlah);
                    var hist = User.GenerateHistory(selectedItemPTI.PTIId, BussinesType.PTI, ChangeType.Update, note);

                    if (!db.Histories.Insert(hist))
                    {
                        throw new SystemException("Item PTI Tidak Berhasil Di Split");
                    }

                    trans.Commit();
                    return(newItem);
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new SystemException(ex.Message);
                }
            }
        }