Ejemplo n.º 1
0
 internal ACTransit.DataAccess.RestroomFinder.Restroom ToDataAccessFrom(ACTransit.DataAccess.RestroomFinder.Restroom restroom)
 {
     restroom.ACTRoute            = ACTRoute;
     restroom.Address             = Address;
     restroom.City                = City;
     restroom.Country             = Country;
     restroom.DrinkingWater       = DrinkingWater;
     restroom.Geo                 = DbGeography.PointFromText(String.Format("POINT({0} {1})", LongDec, LatDec), 4326);
     restroom.LatDec              = LatDec;
     restroom.LongDec             = LongDec;
     restroom.Note                = Note;
     restroom.WeekdayHours        = WeekdayHours;
     restroom.SaturdayHours       = SaturdayHours;
     restroom.SundayHours         = SundayHours;
     restroom.NearestIntersection = NearestIntersection;
     restroom.RestroomName        = RestroomName;
     restroom.RestroomType        = RestroomType;
     restroom.IsToiletAvailable   = IsToiletAvailable;
     restroom.State               = State;
     restroom.Zip                 = Zip;
     restroom.IsPublic            = IsPublic;
     restroom.AverageRating       = AverageRating;
     restroom.UpdDateTime         = DateTime.Now;
     restroom.StatusListId        = Active?(Approved ? (int)RestroomEnums.RestroomApprovalStatus.Approved : (int)RestroomEnums.RestroomApprovalStatus.Pending):(int)RestroomEnums.RestroomApprovalStatus.InActive;
     restroom.ToiletGenderId      = ToiletGenderId;
     restroom.AddressChanged      = AddressChanged;
     restroom.LabelId             = LabelId;
     return(restroom);
 }
        public async Task <Restroom> SaveRestroomAsync(Restroom restroom)
        {
            if (restroom.RestroomId == default)
            {
                restroom = Create(restroom);
            }
            else
            {
                restroom = Update(restroom);
            }
            await SaveChangesAsync();

            return(restroom);
        }
Ejemplo n.º 3
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
            });
        }
Ejemplo n.º 4
0
        //[DataMember(Name = "isPaid")]
        //public bool IsPaid => !(RestroomType == "BART" || RestroomType == "NON-PAID");

        //[DataMember(Name = "isPaid")]
        //public bool IsPaid
        //{
        //    get { return !(RestroomType==null || RestroomType.ToUpper() == "BART" || RestroomType.ToUpper() == "NON-PAID" || RestroomType.ToUpper() == "ACT"); }
        //    set{}
        //}

        internal static Restroom FromDataAccess(ACTransit.DataAccess.RestroomFinder.Restroom restStop)
        {
            return(FromDataAccess(restStop, null));
        }
        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;
            }
        }
Ejemplo n.º 6
0
        public static DBR.Restroom ToEntity(Dto.Restroom restroom)
        {
            if (restroom == null)
            {
                return(null);
            }

            var newRestroom = new DBR.Restroom
            {
                RestroomId             = restroom.RestroomId,
                ContactId              = restroom.ContactId == 0 ? null : restroom.ContactId,
                EquipmentNum           = restroom.EquipmentNum,
                RestroomType           = restroom.RestroomType,
                RestroomName           = restroom.RestroomName,
                Address                = restroom.Address,
                City                   = restroom.City,
                State                  = restroom.State,
                Zip                    = restroom.Zip,
                Country                = restroom.Country,
                DrinkingWater          = restroom.DrinkingWater,
                WeekdayHours           = restroom.WeekdayHours,
                SaturdayHours          = restroom.SaturdayHours,
                SundayHours            = restroom.SundayHours,
                Note                   = restroom.Note,
                NearestIntersection    = restroom.NearestIntersection,
                LongDec                = restroom.LongDec,
                LatDec                 = restroom.LatDec,
                NotificationEmail      = restroom.NotificationEmail,
                CleanedContactId       = restroom.CleanedContactId == 0 ? null : restroom.CleanedContactId,
                RepairedContactId      = restroom.RepairedContactId == 0 ? null : restroom.RepairedContactId,
                SuppliedContactId      = restroom.SuppliedContactId == 0 ? null : restroom.SuppliedContactId,
                SecurityGatesContactId = restroom.SecurityGatesContactId == 0 ? null : restroom.SecurityGatesContactId,
                SecurityLocksContactId = restroom.SecurityLocksContactId == 0 ? null : restroom.SecurityLocksContactId,
                IsToiletAvailable      = restroom.IsToiletAvailable,
                //Active = restroom.Active,
                ToiletGenderId  = restroom.ToiletGenderId,
                AddressChanged  = restroom.AddressChanged,
                LabelId         = restroom.LabelId,
                StatusListId    = restroom.StatusListId,
                Deleted         = restroom.Deleted,
                IsHistory       = restroom.IsHistory,
                IsPublic        = restroom.IsPublic,
                UnavailableFrom = restroom.UnavailableFrom,
                UnavailableTo   = restroom.UnavailableTo,
                Comment         = restroom.Comment
            };

            //Create geography object for the current location
            newRestroom.Geo = System.Data.Entity.Spatial.DbGeography.PointFromText(
                $"POINT({restroom.LongDec} {restroom.LatDec})", 4326);

            //Transform string array of routes into a comma separated values string
            if (restroom.SelectedRoutes != null && restroom.SelectedRoutes.Count() > 0)
            {
                newRestroom.ACTRoute = string.Join(",", restroom.SelectedRoutes);
            }
            else
            {
                newRestroom.ACTRoute = restroom.ACTRoute;
            }

            return(newRestroom);
        }