Esempio n. 1
0
 public override bool DeleteData(int id, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success, Message = "Delete success"
     };
     try
     {
         using (CreditNoteMngEntities context = CreateContext())
         {
             CreditNote dbItem = context.CreditNote.FirstOrDefault(o => o.CreditNoteID == id);
             if (dbItem == null)
             {
                 throw new Exception("Credit note not found!");
             }
             if (dbItem.IsConfirmed != null && (bool)dbItem.IsConfirmed)
             {
                 throw new Exception("Credit note was confirmed. You can not delete");
             }
             context.CreditNote.Remove(dbItem);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
         {
             notification.DetailMessage.Add(ex.InnerException.Message);
         }
         return(false);
     }
 }
Esempio n. 2
0
        public override bool UpdateData(int id, ref DTO.CreditNoteMng.CreditNote dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (CreditNoteMngEntities context = CreateContext())
                {
                    CreditNote dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new CreditNote();
                        context.CreditNote.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.CreditNote.FirstOrDefault(o => o.CreditNoteID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "invoice not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoItem.ConcurrencyFlag_String)))
                        {
                            throw new Exception(DALBase.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        //convert dto to db
                        converter.DTO2DB_CreditNote(dtoItem, ref dbItem);
                        context.SaveChanges();

                        //Update InvoiceNo
                        if (id == 0)
                        {
                            context.CreditNoteMng_function_GenerateInvoiceNo(dbItem.CreditNoteID);
                        }
                        //Get return data
                        dtoItem = GetData(dbItem.CreditNoteID, out notification);
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(false);
            }
        }
Esempio n. 3
0
 public bool Confirm(int id, int confirmedBy, out Library.DTO.Notification notification)
 {
     notification = new Library.DTO.Notification()
     {
         Type = Library.DTO.NotificationType.Success, Message = "Credit note has been confirmed success"
     };
     try
     {
         using (CreditNoteMngEntities context = CreateContext())
         {
             CreditNote dbItem = context.CreditNote.Where(o => o.CreditNoteID == id).FirstOrDefault();
             dbItem.IsConfirmed   = true;
             dbItem.ConfirmedBy   = confirmedBy;
             dbItem.ConfirmedDate = DateTime.Now;
             context.SaveChanges();
         }
         return(true);
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
         {
             notification.DetailMessage.Add(ex.InnerException.Message);
         }
         return(false);
     }
 }