예제 #1
0
 public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
 {
     notification = new Notification()
     {
         Type = NotificationType.Success
     };
     DTO.MasterExchangeRateEdit dtodb = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.MasterExchangeRateEdit>();
     try
     {
         using (MasterExchangeRateMngEntities context = CreateContext())
         {
             MasterExchangeRate dbItem;
             if (id == 0)
             {
                 dbItem = new MasterExchangeRate();
                 context.MasterExchangeRate.Add(dbItem);
             }
             else
             {
                 dbItem = context.MasterExchangeRate.Where(o => o.MasterExchangeRateID == id).FirstOrDefault();
             }
             if (dbItem == null)
             {
                 notification.Message = "Data Not Found !";
                 return(false);
             }
             else
             {
                 converter.DTO2DB_UpdateData(dtodb, ref dbItem);
                 context.SaveChanges();
                 dtoItem = GetData(userId, dbItem.MasterExchangeRateID, out notification);
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         notification.Type    = Library.DTO.NotificationType.Error;
         notification.Message = ex.Message;
         notification.DetailMessage.Add(ex.Message);
         if (ex.GetBaseException() != null)
         {
             notification.DetailMessage.Add(ex.GetBaseException().Message);
         }
         return(false);
     }
 }
예제 #2
0
        public object UpdateIndexData(int userId, object dtoItems, out Notification notification)
        {
            notification = new Notification()
            {
                Type = NotificationType.Success
            };
            List <DTO.UpdateIndexForm> parseData = ((Newtonsoft.Json.Linq.JArray)dtoItems).ToObject <List <DTO.UpdateIndexForm> >();

            try
            {
                using (MasterExchangeRateMngEntities context = CreateContext())
                {
                    foreach (DTO.UpdateIndexForm item in parseData)
                    {
                        MasterExchangeRate masterData = context.MasterExchangeRate.FirstOrDefault(o => o.MasterExchangeRateID == item.MasterExchangeRateID);
                        if (masterData != null)
                        {
                            masterData.ValidDate    = item.ValidDate.ConvertStringToDateTime();
                            masterData.Currency     = item.Currency;
                            masterData.ExchangeRate = item.ExchangeRate;
                        }
                    }
                    context.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(false);
            }
        }
예제 #3
0
 public void DTO2DB_UpdateData(DTO.MasterExchangeRateEdit dtoItem, ref MasterExchangeRate dbItem)
 {
     AutoMapper.Mapper.Map <DTO.MasterExchangeRateEdit, MasterExchangeRate>(dtoItem, dbItem);
     dbItem.ValidDate = dtoItem.ValidDate.ConvertStringToDateTime();
 }