public void InsertCity(dynamic address)
        {
            CM_S_CITY_BOOK Item = new CM_S_CITY_BOOK();

            EntityMapper.UpdateEntity(address, Item);
            Item.DT_INSERT  = Item.DT_UPDATE = DateTime.UtcNow;
            Item.USERINSERT = Item.USERUPDATE = Settings.Value.Username;
            Item.CITY_NAME  = Item.CITY_NAME.ToUpperInvariant();
            Item.ROWGUID    = Guid.NewGuid();
            if (string.IsNullOrWhiteSpace(Item.COUNTRY_CODE))
            {
                Item.COUNTRY_CODE = Settings.Value.CountryCode;
            }

            CM_S_AREA_BOOK Area = null;

            if (!string.IsNullOrWhiteSpace(Item.AREA_CODE))
            {
                Area = DBContext.CM_S_AREA_BOOK.FirstOrDefault(E => E.AREA_CODE == Item.AREA_CODE);
            }

            if (Area == null)             //Revert to default state area, if possibile
            {
                string             StateCode = address.StateCode;
                CM_S_STATE_EXT_AUS State     = DBContext.CM_S_STATE_EXT_AUS.FirstOrDefault(E => E.STATE_CODE == StateCode);
                if (State == null)
                {
                    throw new InvalidOperationException($"Cannot find a state with state code = '{StateCode}'");
                }

                Item.AREA_CODE = State.DEFAULT_AREA_CODE;
            }
            Area = DBContext.CM_S_AREA_BOOK.FirstOrDefault(E => E.AREA_CODE == Item.AREA_CODE);
            if (Area == null)
            {
                throw new InvalidOperationException($"Cannot find area with code = '{Item.AREA_CODE}' for state '{address.StateCode}'");
            }

            CM_S_CITY_BOOK City = DBContext.CM_S_CITY_BOOK.Where(E => E.COUNTRY_CODE == Item.COUNTRY_CODE && E.AREA_CODE == Item.AREA_CODE && E.ZIP_CODE == Item.ZIP_CODE).OrderByDescending(E => E.CITY_COUNTER).FirstOrDefault();

            Item.CITY_COUNTER = (short)(City != null ? City.CITY_COUNTER + 1 : 1);

            DBContext.CM_S_CITY_BOOK.Add(Item);
            DBContext.SaveChanges();
        }
        public override void LoadData <T>(DbContext context, dynamic entity)
        {
            base.LoadData <T>(context, (T)entity);

            DiaryContext     DBContext   = (DiaryContext)context;
            AG_B_APPOINTMENT appointment = (AG_B_APPOINTMENT)entity;

            //EmployeeName = string.Format("{0} {1}", appointment.CM_S_EMPLOYEE?.FIRSTNAME, appointment.CM_S_EMPLOYEE?.LASTNAME);
            EmployeeName       = appointment.CM_S_EMPLOYEE?.EMPLOYEE_DESCR;
            ServiceDescription = appointment.AG_S_SERVICE?.SERVICE_DESCR;

            StatusDescription = DBContext.SY_GENERAL_STATUS.FirstOrDefault(E => E.STATUS_CODE == StatusCode)?.STATUS_DESCR;
            CU_B_ADDRESS_BOOK Customer = DBContext.CU_B_ADDRESS_BOOK.FirstOrDefault(E => E.CUSTOMER_CODE == CustomerCode);

            if (Customer != null)
            {
                CustomerName = string.Format("{0} {1}", Customer.FIRSTNAME, Customer.LASTNAME);
            }
            CM_B_SHOP Shop = DBContext.CM_B_SHOP.FirstOrDefault(E => E.SHOP_CODE == AppointmentShopCode);

            AppointmentShopDescription = Shop?.SHOP_DESCR;
            CM_S_CITY_BOOK_SHOP ShopArea = DBContext.CM_S_CITY_BOOK_SHOP.FirstOrDefault(E => E.SHOP_CODE == AppointmentShopCode);

            AreaCode = ShopArea?.AREA_CODE;
            CM_S_AREA_BOOK AreaBook = DBContext.CM_S_AREA_BOOK.FirstOrDefault(E => E.AREA_CODE == AreaCode);

            AreaDescription = AreaBook?.AREA_DESCR;
            RegionCode      = AreaBook?.REGION_CODE;
            CM_S_REGION_BOOK Region = DBContext.CM_S_REGION_BOOK.FirstOrDefault(E => E.REGION_CODE == RegionCode);

            RegionDescription = Region?.REGION_DESCR;
            CU_B_ACTIVITY activity = DBContext.CU_B_ACTIVITY.FirstOrDefault(E => E.ACTIVITY_TYPE_CODE == "PR" && E.CUSTOMER_CODE == appointment.CUSTOMER_CODE && E.APPOINTMENT_ID == appointment.APPOINTMENT_ID);

            MediaTypeDescription = activity?.CM_S_MEDIATYPE?.MEDIATYPE_DESCR;
            AG_S_ROOM room = DBContext.AG_S_ROOM.FirstOrDefault(E => E.SHOP_CODE == appointment.APPOINTMENT_SHOP_CODE && E.ROOM_CODE == appointment.ROOM_CODE);

            RoomDescription = room?.ROOM_DESCR;
        }