Esempio n. 1
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.LedgerAccount dtoLedgerAccount = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.LedgerAccount>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (LedgerAccountMngEntities context = CreateContext())
                {
                    LedgerAccount dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new LedgerAccount();
                        context.LedgerAccount.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.LedgerAccount.FirstOrDefault(o => o.LedgerAccountID == id);
                    }

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

                        converter.DTO2BD(dtoLedgerAccount, ref dbItem);

                        dbItem.UpdatedDate = DateTime.Now;
                        dbItem.UpdatedBy   = userId;

                        context.SaveChanges();

                        dtoItem = GetData(dbItem.LedgerAccountID, out notification).Data;

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
Esempio n. 2
0
 public void DTO2BD(DTO.LedgerAccount dtoItem, ref LedgerAccount dbItem)
 {
     AutoMapper.Mapper.Map <DTO.LedgerAccount, LedgerAccount>(dtoItem, dbItem);
     dbItem.UpdatedDate = DateTime.Now;
 }