Esempio n. 1
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);
            }
        }