public bool DeleteByEvent(int id)
        {
            try
            {
                var eventGenreDtos = GetByEvent(id);

                if (eventGenreDtos == null)
                {
                    _logger.LogError($"EventGenres with event id: {id}, haven't been found in db.");
                    return(false);
                }

                foreach (EventGenreDto eventGenreDto in eventGenreDtos)
                {
                    EventGenre eventGenre = _mapper.Map <EventGenre>(eventGenreDto);
                    _repository.Delete(eventGenre);
                }

                _repository.Save();

                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside DeleteEventGenre action: {ex.Message}");
                throw new Exception();
            }
        }
Example #2
0
        private EventGenre AddGenre(EventGenre model)
        {
            var gnr = db.EventGenres.FirstOrDefault(o => o.Name.ToLower().Equals(model.Name.ToLower()));

            if (gnr != null)
            {
                return(gnr);
            }
            gnr = model;
            db.EventGenres.Add(gnr);
            db.SaveChanges();
            return(gnr);
        }
        /// <summary>
        /// A function which attempts to save values to the database
        /// </summary>
        /// <returns>Boolean values</returns>
        private bool SaveCustomerChanges()
        {
            //Initialization of bool
            bool output = false;

            //Assigns the value of the helper class to the class
            bool isNull = ArePropertiesNotNull(CurrentEvent);

            //Assign a context value
            CustomerDatabaseEntities context = new CustomerDatabaseEntities();

            //If the check for not null is not true
            if (!isNull)
            {
                //Using the helper function which converts the image to bytes
                byte[] imageBytes  = ConvertImageToByteArray(ImagePathOfEventImage);
                byte[] imageBytes2 = ConvertImageToByteArray(ImagePathOfEventLayout);

                #region Saving to the database

                CurrentEvent.eventPicture     = imageBytes;
                CurrentEvent.eventLayout      = imageBytes2;
                CurrentEvent.eventGenre       = EventGenre.Trim();
                CurrentEvent.eventTitle       = EventTitle.Trim();
                CurrentEvent.showOnHomePage   = ShowOnHomePage.Value;
                CurrentEvent.eventDescription = EventDescription.Trim();
                CurrentEvent.eventStart       = EventStart;
                CurrentEvent.eventEnd         = EventEnd;
                CurrentEvent.capacity         = Capacity;
                CurrentEvent.eventLocation    = EventLocation.Trim();
                CurrentEvent.eventAddress     = EventAddress.Trim();
                context.Event_Details.Add(CurrentEvent);

                //Save changes to the database
                context.SaveChanges();
                context.Dispose();

                #endregion

                //Return true if this function succeeds
                output = true;
                return(output);
            }

            //Otherwise return false
            return(output);
        }
        public bool Create(EventGenreForCreationDto eventGenre)
        {
            try
            {
                EventGenre DataEntity = _mapper.Map <EventGenre>(eventGenre);

                _repository.Create(DataEntity);
                _repository.Save();

                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside CreateEvent action: {ex.Message}");
                throw new Exception();
            }
        }
        public bool Delete(int event_id, int genre_id)
        {
            try
            {
                var eventGenreDto = GetByIds(event_id, genre_id);

                if (eventGenreDto == null)
                {
                    return(false);
                }

                EventGenre eventGenre = _mapper.Map <EventGenre>(eventGenreDto);

                _repository.Delete(eventGenre);
                _repository.Save();

                return(true);
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside DeleteEventGenre action: {ex.Message}");
                throw new Exception();
            }
        }
 public void Update(EventGenre model)
 {
     //throw new NotImplementedException();
 }
 public void Delete(EventGenre eventGenre)
 {
     _eventGenres.Remove(eventGenre);
 }
Example #8
0
 public async Task UpdateEventGenre(EventGenre eventGenre)
 {
     _dataContext.Update(eventGenre);
     await _dataContext.SaveChangesAsync();
 }
Example #9
0
 public async Task DeleteEventGenre(EventGenre eventGenre)
 {
     eventGenre.Deleted = true;
     _dataContext.Update(eventGenre);
     await _dataContext.SaveChangesAsync();
 }
Example #10
0
 public async Task CreateEventGenre(EventGenre eventGenre)
 {
     eventGenre.Deleted = false;
     _dataContext.Add(eventGenre);
     await _dataContext.SaveChangesAsync();
 }