internal async Task <Restroom> GetRestroomAsync(int restroomId)
        {
            Entity.Contact contact   = null;
            var            restroomD = await RestroomUnitOfWork.GetRestroomAsync(restroomId);

            if (restroomD != null && restroomD.ContactId.HasValue)
            {
                contact = RestroomUnitOfWork.GetById <Entity.Contact, int>(restroomD.ContactId.Value);
            }

            return(restroomD == null ? null : Restroom.FromDataAccess(restroomD, contact));
        }
Пример #2
0
        public static Dto.Contact ToModel(DBR.Contact contact)
        {
            if (contact == null)
            {
                return(null);
            }

            return(new Dto.Contact
            {
                ContactId = contact.ContactId,
                ServiceProvider = contact.ServiceProvider,
                Name = contact.ContactName,
                Title = contact.Title,
                Phone = contact.Phone,
                Email = contact.Email,
                Address = contact.Address,
                Notes = contact.Notes
            });
        }
Пример #3
0
        public static DBR.Contact ToEntity(Dto.Contact contact)
        {
            if (contact == null)
            {
                return(null);
            }

            var newContact = new DBR.Contact
            {
                ContactId       = contact.ContactId,
                ServiceProvider = contact.ServiceProvider,
                ContactName     = contact.Name,
                Title           = contact.Title,
                Email           = contact.Email,
                Address         = contact.Address,
                Phone           = contact.Phone,
                Notes           = contact.Notes
            };

            return(newContact);
        }
Пример #4
0
        internal static Restroom FromDataAccess(ACTransit.DataAccess.RestroomFinder.Restroom restStop, ACTransit.DataAccess.RestroomFinder.Contact contact)
        {
            return(new Restroom
            {
                ACTRoute = restStop.ACTRoute,
                Address = restStop.Address,
                City = restStop.City,
                Country = restStop.Country,
                DrinkingWater = restStop.DrinkingWater,
                Geo = restStop.Geo,
                LatDec = restStop.LatDec,
                LongDec = restStop.LongDec,
                Note = restStop.Note,
                WeekdayHours = restStop.WeekdayHours,
                SaturdayHours = restStop.SaturdayHours,
                SundayHours = restStop.SundayHours,
                NearestIntersection = restStop.NearestIntersection,
                RestroomName = restStop.RestroomName,
                RestroomId = restStop.RestroomId,
                RestroomType = restStop.RestroomType,
                IsToiletAvailable = restStop.IsToiletAvailable,
                State = restStop.State,
                Zip = restStop.Zip,
                IsHistory = restStop.IsHistory,
                IsPublic = restStop.IsPublic,
                AverageRating = restStop.AverageRating,
                Approved = restStop.StatusListId.GetValueOrDefault(2) == 2,
                Active = restStop.StatusListId.GetValueOrDefault() == (int)RestroomEnums.RestroomApprovalStatus.Approved,
                ToiletGenderId = restStop.ToiletGenderId,
                AddressChanged = restStop.AddressChanged,
                LabelId = restStop.LabelId,
                ContactName = contact?.ContactName,
                ContactTitle = contact?.Title,
                ContactEmail = contact?.Email,
                ContactPhone = contact?.Phone,
                ServiceProvider = contact?.ServiceProvider,

                //Active = restStop.Active
            });
        }
        internal async Task <Restroom> SaveRestroomAsync(Restroom model)
        {
            Entity.Restroom restroom = null;
            if (model.RestroomId > 0)
            {
                var r = await RestroomUnitOfWork.GetRestroomAsync(model.RestroomId);

                restroom = model.ToDataAccessFrom(r);
                Logger.WriteDebug("SaveRestroomAsync->After GetRestroomAsync and ToDataAccessFrom:" + JsonConvert.SerializeObject(restroom));
            }
            else
            {
                restroom           = model.ToDataAccess();
                restroom.UpdUserId = CurrentUserName;
            }

            var hasContact     = false;
            var contactChanged = false;


            hasContact = !string.IsNullOrWhiteSpace(model.ContactName) ||
                         !string.IsNullOrWhiteSpace(model.ContactTitle) ||
                         !string.IsNullOrWhiteSpace(model.ContactEmail) ||
                         !string.IsNullOrWhiteSpace(model.ContactPhone);
            Entity.Contact contact = null;

            if (!hasContact && restroom.ContactId.HasValue && restroom.ContactId > 0)
            {
                restroom.ContactId = null;
                restroom.Contact   = null;
            }

            else if (restroom.ContactId.HasValue && restroom.ContactId > 0)
            {
                contact = await RestroomUnitOfWork.GetByIdAsync <Entity.Contact, int>(restroom.ContactId.Value);

                if (contact.ContactName != model.ContactName ||
                    contact.Title != model.ContactTitle ||
                    contact.Email != model.ContactEmail ||
                    contact.Phone != model.ContactPhone ||
                    contact.ServiceProvider != model.ServiceProvider
                    )
                {
                    contactChanged = true;
                }
            }

            if (contactChanged || (hasContact && (!restroom.ContactId.HasValue || restroom.ContactId == 0)))
            {
                contact = new Entity.Contact
                {
                    Title           = model.ContactTitle,
                    Email           = model.ContactEmail,
                    Phone           = model.ContactPhone,
                    ContactName     = model.ContactName,
                    ServiceProvider = model.ServiceProvider
                };
                contact          = RestroomUnitOfWork.Create(contact);
                restroom.Contact = contact;
            }


            //restroom.Active = true;
            restroom.StatusListId = 1;  // always pending...
            try
            {
                var savedModel = await RestroomUnitOfWork.SaveRestroomAsync(restroom);

                return(savedModel == null ? null : Restroom.FromDataAccess(savedModel));
            }
            catch (DbEntityValidationException ex)
            {
                var errTxt = ex.GetStringRepresentation();
                Logger.WriteError("RestroomHandler.SaveRestroomAsync.DbEntityValidationException -> EntityValidationErrors : \r\n" + errTxt);
                throw;
            }
        }