Beispiel #1
0
        public void DTO2DB_BifaTelephone(int userID, DTO.BifaTelephone dtoItem, ref BifaTelephone dbItem)
        {
            AutoMapper.Mapper.Map <DTO.BifaTelephone, BifaTelephone>(dtoItem, dbItem);

            dbItem.BifaCompanyID = dtoItem.BifaCompanyID;
            dbItem.UpdatedBy     = userID;
            dbItem.UpdatedDate   = System.DateTime.Now;
        }
        public object UpdateTelephone(int userID, int id, System.Collections.Hashtable filters, out Library.DTO.Notification notification)
        {
            notification      = new Library.DTO.Notification();
            notification.Type = Library.DTO.NotificationType.Success;

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

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

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

                        context.BifaTelephone.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.BifaTelephone.FirstOrDefault(o => o.BifaTelephoneID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Type    = Library.DTO.NotificationType.Error;
                        notification.Message = "Can not find bifa telephone!";
                    }
                    else
                    {
                        converter.DTO2DB_BifaTelephone(userID, dtoItem, ref dbItem);
                        context.SaveChanges();

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

            return(dtoItem);
        }
Beispiel #3
0
        public void DTO2DB_BifaPerson(int userID, DTO.BifaPerson dtoItem, ref BifaPerson dbItem)
        {
            AutoMapper.Mapper.Map <DTO.BifaPerson, BifaPerson>(dtoItem, dbItem);
            dbItem.DateOfBirth   = dtoItem.DateOfBirth.ConvertStringToDateTime();
            dbItem.UpdatedBy     = userID;
            dbItem.UpdatedDate   = System.DateTime.Now;
            dbItem.BifaCompanyID = dtoItem.BifaCompanyID;

            if (dtoItem.BifaEmailAddresses != null)
            {
                foreach (var item in dbItem.BifaEmailAddress.ToArray())
                {
                    if (!dtoItem.BifaEmailAddresses.Select(s => s.BifaEmailAddressID).Contains(item.BifaEmailAddressID))
                    {
                        dbItem.BifaEmailAddress.Remove(item);
                    }
                }

                foreach (var dtoEmailAddress in dtoItem.BifaEmailAddresses.ToArray())
                {
                    BifaEmailAddress dbEmailAddress;

                    if (dtoEmailAddress.BifaEmailAddressID < 0)
                    {
                        dbEmailAddress = new BifaEmailAddress();
                        dbItem.BifaEmailAddress.Add(dbEmailAddress);
                    }
                    else
                    {
                        dbEmailAddress = dbItem.BifaEmailAddress.FirstOrDefault(s => s.BifaEmailAddressID == dtoEmailAddress.BifaEmailAddressID);
                    }

                    if (dbEmailAddress != null)
                    {
                        AutoMapper.Mapper.Map <DTO.BifaEmailAddress, BifaEmailAddress>(dtoEmailAddress, dbEmailAddress);
                        dbEmailAddress.UpdatedBy   = userID;
                        dbEmailAddress.UpdatedDate = System.DateTime.Now;
                    }
                }
            }

            if (dtoItem.BifaTelephones != null)
            {
                foreach (var item in dbItem.BifaTelephone.ToArray())
                {
                    if (!dtoItem.BifaTelephones.Select(s => s.BifaTelephoneID).Contains(item.BifaTelephoneID))
                    {
                        dbItem.BifaTelephone.Remove(item);
                    }
                }

                foreach (var dtoTelephone in dtoItem.BifaTelephones.ToArray())
                {
                    BifaTelephone dbTelephone;

                    if (dtoTelephone.BifaTelephoneID < 0)
                    {
                        dbTelephone = new BifaTelephone();
                        dbItem.BifaTelephone.Add(dbTelephone);
                    }
                    else
                    {
                        dbTelephone = dbItem.BifaTelephone.FirstOrDefault(s => s.BifaTelephoneID == dtoTelephone.BifaTelephoneID);
                    }

                    if (dbTelephone != null)
                    {
                        AutoMapper.Mapper.Map <DTO.BifaTelephone, BifaTelephone>(dtoTelephone, dbTelephone);
                        dbTelephone.UpdatedBy   = userID;
                        dbTelephone.UpdatedDate = System.DateTime.Now;
                    }
                }
            }
        }