Example #1
0
        public static void UpdatePerson(InvoiceModle person)
        {
            lock (LockObj)
            {
                var          persons        = InvoiceModle.Storage;
                InvoiceModle updatingPerson = persons.FirstOrDefault(p => p.Id == person.Id);

                if (updatingPerson == null)
                {
                    throw new Exception("InvoiceModle not found");
                }
                updatingPerson.UId         = person.UId;
                updatingPerson.InvoiceNo   = person.InvoiceNo;
                updatingPerson.AmountNoTax = person.AmountNoTax;
                updatingPerson.InvoiceDate = person.InvoiceDate;
                try
                {
                    UpdateToDatabase(updatingPerson);
                }
                catch (Exception e)
                {
                    throw;
                }
                InvoiceModle.Storage = persons;
            }
        }
Example #2
0
 private static void UpdateToDatabase(InvoiceModle updatingPerson)
 {
     using (Entities db = new Entities())
     {
         if (updatingPerson.UId == null || db.T_FD_InvoiceList.Find(updatingPerson.UId) == null)
         {
             db.T_FD_InvoiceList.Add(new T_FD_InvoiceList()
             {
                 AmountNoTax = updatingPerson.AmountNoTax,
                 InvoiceDate = updatingPerson.InvoiceDate,
                 InvoiceNo   = updatingPerson.InvoiceNo,
                 ReferenceId = ReferenceId
             });
         }
         else
         {
             var dbItem = db.T_FD_InvoiceList.Find(updatingPerson.UId);
             dbItem.AmountNoTax = updatingPerson.AmountNoTax;
             dbItem.InvoiceDate = updatingPerson.InvoiceDate;
             dbItem.InvoiceNo   = updatingPerson.InvoiceNo;
             dbItem.ReferenceId = ReferenceId;
         }
         db.SaveChanges();
     }
 }
Example #3
0
 private static void DeleteTFromDatabase(InvoiceModle updatingPerson)
 {
     using (Entities db = new Entities())
     {
         var dbItem = db.T_FD_InvoiceList.Find(updatingPerson.UId);
         if (dbItem == null)
         {
             return;
         }
         db.T_FD_InvoiceList.Remove(dbItem);
         db.SaveChanges();
     }
 }
Example #4
0
        public static int?AddPerson(InvoiceModle person)
        {
            lock (LockObj)
            {
                var persons = InvoiceModle.Storage;
                person.Id = InvoiceModle.NewId;
                try
                {
                    UpdateToDatabase(person);
                }
                catch (Exception e)
                {
                    throw;
                }
                persons.Add(person);
                InvoiceModle.Storage = persons;

                return(person.Id);
            }
        }
Example #5
0
        public static void DeletePerson(int id)
        {
            lock (LockObj)
            {
                var          persons = InvoiceModle.Storage;
                InvoiceModle person  = persons.FirstOrDefault(p => p.Id == id);

                if (person == null)
                {
                    throw new Exception("InvoiceModle not found");
                }
                try
                {
                    DeleteTFromDatabase(person);
                }
                catch (Exception e)
                {
                    throw;
                }
                persons.Remove(person);

                InvoiceModle.Storage = persons;
            }
        }