public object UpdateBifaAddress(int userID, System.Collections.Hashtable filters, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

            int id = (filters.ContainsKey("id") && filters["id"] != null && !string.IsNullOrEmpty(filters["id"].ToString().Trim())) ? System.Convert.ToInt32(filters["id"].ToString().Trim()) : 0;

            DTO.BifaAddress dtoItem = ((Newtonsoft.Json.Linq.JObject)filters["view"]).ToObject <DTO.BifaAddress>();

            try
            {
                using (var context = CreateContext())
                {
                    BifaAddress dbItem;

                    if (id == 0)
                    {
                        dbItem = new BifaAddress();

                        context.BifaAddress.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.BifaAddress.FirstOrDefault(o => o.BifaAddressID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Type    = Library.DTO.NotificationType.Error;
                        notification.Message = "Can not find Bifa address!";
                    }
                    else
                    {
                        converter.DTO2DB_BifaAddress(dtoItem, ref dbItem);

                        dbItem.BifaCompanyID = dtoItem.BifaCompanyID;
                        dbItem.UpdatedBy     = userID;
                        dbItem.UpdatedDate   = System.DateTime.Now;

                        context.SaveChanges();

                        dtoItem = AutoMapper.Mapper.Map <BifaCompanyMng_BifaAddress_View, DTO.BifaAddress>(context.BifaCompanyMng_BifaAddress_View.FirstOrDefault(o => o.BifaAddressID == dbItem.BifaAddressID));
                    }
                }
            }
            catch (System.Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = Helper.GetInnerException(ex).Message;
            }

            return(dtoItem);
        }
Exemple #2
0
 public void DTO2DB_BifaAddress(DTO.BifaAddress dtoItem, ref BifaAddress dbItem)
 {
     AutoMapper.Mapper.Map <DTO.BifaAddress, BifaAddress>(dtoItem, dbItem);
 }