Пример #1
0
 public BikeRef(BusinessEntities.Bikes.Bike bike)
 {
     if (bike != null)
     {
         this.BikeId    = bike.BikeId;
         this.BikeModel = new BikeModelRef(bike.BikeModel);
         this.Color     = bike.Color;
     }
 }
Пример #2
0
 public Bike(BusinessEntities.Bikes.Bike bike, Location?currentLocation)
     : base(bike, currentLocation)
 {
     if (bike != null)
     {
         this.Created   = bike.CreatedUtc;
         this.CreatedBy = new UserRef(bike.CreatedBy);
     }
 }
Пример #3
0
        /// <summary>
        /// Update single entity
        /// </summary>
        public void Put(Models.Bikes.Bike bike)
        {
            using (var scope = Scope("Put"))
            {
                // authorize
                AuthProvider.Authorize(Permission.Bike_Management); // throws UnauthorizedException or we have CurrentUser after this

                // prepare
                Helper.Expect(bike, bike.BikeId);

                // validate
                Helper.ValidateModel(bike, true);

                // process
                var saveImage = !string.IsNullOrEmpty(bike.ImageToUploadContentBase64) && !string.IsNullOrEmpty(bike.ImageToUploadFileName);
                var entity    = bike.ToEntity();
                BusinessEntities.Bikes.Bike prevEntity = null;

                if (saveImage)
                {
                    prevEntity = BikeManager.GetById(entity.BikeId);

                    // increment seq
                    entity.ImageSeq    = prevEntity.ImageSeq.GetValueOrDefault() + 1;
                    entity.ImageFormat = ContentManager.GetFormat(BikeManager.GetImageContentRef(entity, false)).FileFormat.GetValueOrDefault(); // image will be validated when saving
                }

                BikeManager.Update(entity);

                scope.Complete(
                    () =>
                {
                    // after commit
                    if (saveImage)
                    {
                        // delete previous image
                        if (prevEntity.ImageSeq.HasValue && prevEntity.ImageFormat.HasValue)
                        {
                            BikeManager.DeleteImage(prevEntity);
                        }

                        // save new image
                        BikeManager.SaveImage(entity, ContentManager.DecodeBase64Image(bike.ImageToUploadContentBase64));
                    }
                },
                    () => $"Bike has been updated with Id={bike.BikeId}.");
            }
        }
Пример #4
0
        public BikeListItem(BusinessEntities.Bikes.Bike bike, Location?currentLocation)
            : base(bike)
        {
            if (bike != null)
            {
                this.BikeModel           = new BikeModel(bike.BikeModel);
                this.BikeState           = bike.BikeState;
                this.CurrentLocation     = bike.CurrentLocation;
                this.AvailableFromUtc    = bike.AvailableFromUtc;
                this.RateAverage         = bike.RateAverage;
                this.CurrentLocationName = bike.CurrentLocationName;
                this.ImageSeq            = bike.ImageSeq;

                if (currentLocation.HasValue)
                {
                    this.DistanceMiles = Location.DistanceMiles(bike.CurrentLocation, currentLocation.Value);
                }
            }
        }