public EntityResult <FoodTruck> CreateFoodTruck(CreateFoodTruckInfo foodTruckInfo)
        {
            try
            {
                // Creates our Food Truck object
                var foodTruck = new FoodTruck(foodTruckInfo.Name, foodTruckInfo.Description, foodTruckInfo.Website);

                // Converts tag strings into tag objects (including creating tags that don't exist)
                var tagObjects = this.DecodeTags(foodTruckInfo.Tags);

                // Attaches the tags to the Food Truck Object
                tagObjects.ForEach(obj => foodTruck.AddTag(obj));

                // Persist to the database
                this.foodTruckRepository.Save(foodTruck);
                this.UnitOfWork.SaveChanges();

                return(EntityResult <FoodTruck> .Success(foodTruck));
            }
            catch (Exception ex)
            {
                Logger.LogError(new EventId(104), ex, $"Error thrown while calling FoodTruckService.CreateFoodTruck()");
                return(EntityResult <FoodTruck> .Error("An error occured processing your request"));
            }
        }
        public EntityResult <Location> UpdateLocation(UpdateLocationInfo locationInfo)
        {
            try
            {
                Location location = this.locationRepository.GetLocation(locationInfo.LocationId);

                if (location == null)
                {
                    return(EntityResult <Location> .Failure($"No location was found with the id {locationInfo.LocationId}"));
                }

                // Update the properties
                location.Name          = locationInfo.Name;
                location.StreetAddress = locationInfo.StreetAddress;
                location.City          = locationInfo.City;
                location.State         = locationInfo.State;
                location.ZipCode       = locationInfo.ZipCode;

                this.locationRepository.Save(location);
                this.UnitOfWork.SaveChanges();

                return(EntityResult <Location> .Success(location));
            }
            catch (Exception ex)
            {
                Logger.LogError(new EventId(101), ex, "Error thrown while calling LocationService.CreateLocation()");
                return(EntityResult <Location> .Error("An error occured processing your request"));
            }
        }
 public EntityResult <FoodTruck> GetFoodTruck(int id)
 {
     try
     {
         var foodTruck = this.foodTruckRepository.GetFoodTruck(id);
         return(EntityResult <FoodTruck> .Success(foodTruck));
     }
     catch (Exception ex)
     {
         Logger.LogError(new EventId(103), ex, $"Error thrown while calling FoodTruckService.GetFoodTruck(), id={id}");
         return(EntityResult <FoodTruck> .Error("An error occured processing your request"));
     }
 }
 public EntityResult <List <FoodTruck> > GetFoodTrucksByTag(String tag)
 {
     try
     {
         var foodTrucks = this.foodTruckRepository.GetFoodTruckByTag(tag);
         return(EntityResult <List <FoodTruck> > .Success(foodTrucks.ToList()));
     }
     catch (Exception ex)
     {
         Logger.LogError(new EventId(102), ex, $"Error thrown while calling FoodTruckService.GetFoodTrucksByTag(), tag={tag}");
         return(EntityResult <List <FoodTruck> > .Error("An error occured processing your request"));
     }
 }
 public EntityResult <List <FoodTruck> > GetAllFoodTrucks()
 {
     try
     {
         var foodTrucks = this.foodTruckRepository.GetAllFoodTrucks();
         return(EntityResult <List <FoodTruck> > .Success(foodTrucks.ToList()));
     }
     catch (Exception ex)
     {
         Logger.LogError(new EventId(101), ex, "Error thrown while calling FoodTruckService.GetAllFoodTrucks()");
         return(EntityResult <List <FoodTruck> > .Error("An error occured processing your request"));
     }
 }
 public EntityResult <List <Location> > GetLocations()
 {
     try
     {
         var locations = this.locationRepository.GetLocations();
         return(EntityResult <List <Location> > .Success(locations));
     }
     catch (Exception ex)
     {
         Logger.LogError(new EventId(101), ex, "Error thrown while calling LocationService.GetLocation()");
         return(EntityResult <List <Location> > .Error("An error occured processing your request"));
     }
 }
Beispiel #7
0
 public EntityResult <Tag> GetTagByName(string tagName)
 {
     try
     {
         var tag = this.tagRepository.GetTagByName(tagName);
         return(EntityResult <Tag> .Success(tag));
     }
     catch (Exception ex)
     {
         Logger.LogError(new EventId(101), ex, "Error thrown while calling TagService.GetTagByName()");
         return(EntityResult <Tag> .Error("An error occured processing your request"));
     }
 }
Beispiel #8
0
 public EntityResult <IList <Tag> > GetTagsInUse()
 {
     try
     {
         var tags = this.tagRepository.GetAllTagsInUse();
         return(EntityResult <IList <Tag> > .Success(tags));
     }
     catch (Exception ex)
     {
         Logger.LogError(new EventId(101), ex, "Error thrown while calling TagService.GetTagsInUse()");
         return(EntityResult <IList <Tag> > .Error("An error occured processing your request"));
     }
 }
        public EntityResult <FoodTruck> UpdateFoodTruck(UpdateFoodTruckInfo foodTruckInfo)
        {
            try
            {
                // Creates our Food Truck object
                var foodTruck = this.foodTruckRepository.GetFoodTruck(foodTruckInfo.FoodTruckId);

                if (foodTruck == null)
                {
                    return(EntityResult <FoodTruck> .Failure($"No food truck was found with the id {foodTruckInfo.FoodTruckId}"));
                }

                // Handle Properties
                foodTruck.Name        = foodTruckInfo.Name;
                foodTruck.Description = foodTruckInfo.Description;
                foodTruck.Website     = foodTruckInfo.Website;

                // Deal with the tags
                var inputTags = foodTruckInfo.Tags;    // For convenience

                // Handle Tags on Object but not in Input list (i.e. tags to be removed)
                var removedTags = foodTruck.Tags.WhereNotExists(inputTags, (foodTruckTag, inputTag) => (foodTruckTag.Tag.Text == inputTag));
                removedTags.ToList().ForEach(removedTag => foodTruck.RemoveTag(removedTag));

                // Now deal with the tags that are on the object
                var newTags = inputTags.WhereNotExists(foodTruck.Tags, (inputTag, foodTruckTag) => (inputTag == foodTruckTag.Tag.Text));

                // Converts tag strings into tag objects (including creating tags that don't exist)
                var tagObjects = this.DecodeTags(newTags);

                // Attaches the tags to the Food Truck Object
                tagObjects.ForEach(obj => foodTruck.AddTag(obj));

                // Persist the changes to the database
                this.foodTruckRepository.Save(foodTruck);
                this.UnitOfWork.SaveChanges();

                return(EntityResult <FoodTruck> .Success(foodTruck));
            }
            catch (Exception ex)
            {
                Logger.LogError(new EventId(104), ex, $"Error thrown while calling FoodTruckService.UpdateFoodTruck()");
                return(EntityResult <FoodTruck> .Error("An error occured processing your request"));
            }
        }
        public EntityResult <Location> CreateLocation(CreateLocationInfo locationInfo)
        {
            try
            {
                Location location = new Location(locationInfo.Name, locationInfo.StreetAddress, locationInfo.City,
                                                 locationInfo.State, locationInfo.ZipCode);

                this.locationRepository.Save(location);
                this.UnitOfWork.SaveChanges();

                return(EntityResult <Location> .Success(location));
            }
            catch (Exception ex)
            {
                Logger.LogError(new EventId(101), ex, "Error thrown while calling LocationService.CreateLocation()");
                return(EntityResult <Location> .Error("An error occured processing your request"));
            }
        }
Beispiel #11
0
        public EntityResult <Tag> CreateNewTag(string tagText)
        {
            try
            {
                Tag tag = new Tag(tagText);

                this.tagRepository.SaveTag(tag);
                this.UnitOfWork.SaveChanges();


                return(EntityResult <Tag> .Success(tag));
            }
            catch (Exception ex)
            {
                Logger.LogError(new EventId(101), ex, "Error thrown while calling TagService.CreateNewTag()");
                return(EntityResult <Tag> .Error("An error occured processing your request"));
            }
        }
Beispiel #12
0
        public EntityResult <Tag> UpdateTag(UpdateTagInfo tagInfo)
        {
            try
            {
                Tag tag = this.tagRepository.GetTagById(tagInfo.TagId);

                if (tag == null)
                {
                    return(EntityResult <Tag> .Failure($"No tag was found to update with the id of {tagInfo.TagId}"));
                }

                tag.Text = tagInfo.TagText;

                this.tagRepository.SaveTag(tag);
                this.UnitOfWork.SaveChanges();

                return(EntityResult <Tag> .Success(tag));
            }
            catch (Exception ex)
            {
                Logger.LogError(new EventId(101), ex, "Error thrown while calling TagService.UpdateTag()");
                return(EntityResult <Tag> .Error("An error occured processing your request"));
            }
        }