Exemplo n.º 1
0
        public int AddLocationType(LocationTypeRequest request)
        {
            if (request == null)
            {
                return(-1);
            }

            var locationType = Mapper.Map <LocationType>(request);

            locationType.Checks  = request.CheckIds.Select(c => _friendlyContext.Checks.Find(c)).ToList();
            locationType.Ratings = request.RatingIds.Select(r => _friendlyContext.Ratings.Find(r)).ToList();
            _friendlyContext.LocationTypes.Add(locationType);
            _friendlyContext.SaveChanges();
            return(locationType.Id);
        }
Exemplo n.º 2
0
        public int AddLocation(LocationRequest request)
        {
            if (request == null)
            {
                return(-1);
            }

            var location = Mapper.Map <Location>(request);

            location.LocationType = _friendlyContext.LocationTypes.FirstOrDefault(x => x.Id == request.LocationTypeId);
            _friendlyContext.Locations.Add(location);

            _friendlyContext.SaveChanges();

            return(location.Id);
        }
Exemplo n.º 3
0
        public int AddTag(TagRequest request)
        {
            if (request == null)
            {
                return(-1);
            }

            var tag = new Tag
            {
                Description = request.TagDescription
            };

            _friendlyContext.Tags.Add(tag);
            _friendlyContext.SaveChanges();
            return(tag.Id);
        }
Exemplo n.º 4
0
        public int AddCheck(CheckRequest request)
        {
            if (request == null)
            {
                return(-1);
            }

            var check = new Check
            {
                Description = request.CheckDescription,
                Tag         = _friendlyContext.Tags.Find(request.TagId)
            };

            _friendlyContext.Checks.Add(check);
            _friendlyContext.SaveChanges();
            return(check.Id);
        }
Exemplo n.º 5
0
        public int AddRating(RatingRequest request)
        {
            if (request == null)
            {
                return(-1);
            }

            var rating = new Rating
            {
                Description = request.RatingDescription,
                Tag         = _friendlyContext.Tags.Find(request.TagId)
            };

            _friendlyContext.Ratings.Add(rating);
            _friendlyContext.SaveChanges();
            return(rating.Id);
        }
Exemplo n.º 6
0
        public async Task <HttpResponseMessage> DeleteImage(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Must provide valid id."));
            }

            var image = _friendlyContext.ImageLinks.Find(id);

            if (image == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Cannot find image with provided id."));
            }
            ;

            _friendlyContext.ImageLinks.Remove(image);

            try
            {
                _friendlyContext.SaveChanges();
                var storageConnection = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ToString();
                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnection);
                CloudBlobClient     blobClient     = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer  container      = blobClient.GetContainerReference("location-images");
                if (!container.Exists())
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Container 'location-images' does not exist."));
                }
                ;

                CloudBlockBlob blockBlob = container.GetBlockBlobReference(id);

                await blockBlob.DeleteIfExistsAsync();
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, "Deleted successfully"));;
        }