Esempio n. 1
0
        public ToastDto ToDto()
        {
            List <TagDto> tags = new List <TagDto>();

            if (ToastTags != null)
            {
                foreach (ToastTag toastTag in ToastTags)
                {
                    tags.Add(toastTag.Tag.ToDto());
                }

                ToastDto dto = new ToastDto()
                {
                    Id        = this.Id,
                    ToastText = this.ToastText,
                    Reviewed  = this.Reviewed,
                    Tags      = tags
                };
                return(dto);
            }
            else
            {
                ToastDto dto = new ToastDto()
                {
                    Id        = this.Id,
                    ToastText = this.ToastText,
                    Reviewed  = this.Reviewed,
                    Tags      = new List <TagDto>()
                };
                return(dto);
            }
        }
Esempio n. 2
0
        public async Task <ToastDto> UpdateAsync(Guid id, ToastDto updatedToast)
        {
            if (updatedToast == null || id != updatedToast.Id)
            {
                throw new ArgumentException("Angegebener Trinkspruch ist null oder Id stimmt nicht mit der Id des Trinkspruches überein.");
            }

            Toast existingToast = await toastRepository.GetAsync(t => t.Id == id);

            if (existingToast == null)
            {
                throw new ArgumentException("Angegebene Id ist falsch");
            }

            existingToast.Reviewed  = updatedToast.Reviewed;
            existingToast.ToastText = updatedToast.ToastText;

            try
            {
                List <Tag> existingTags = existingToast.ToastTags.Select(tt => tt.Tag).ToList();
                List <Tag> updatedTags  = new List <Tag>();
                foreach (TagDto tagDto in updatedToast.Tags)
                {
                    Tag tag = await tagRepository.GetAsync(t => t.Id == tagDto.Id);

                    updatedTags.Add(tag);
                }

                List <Tag> tagsToAdd = updatedTags.Except(existingTags).ToList();
                foreach (Tag tagToAdd in tagsToAdd)
                {
                    ToastTag toastTagToAdd = new ToastTag()
                    {
                        TagId   = tagToAdd.Id,
                        ToastId = existingToast.Id
                    };
                    toastTagRepository.Create(toastTagToAdd);
                }

                List <Tag> tagsToDelete = existingTags.Except(updatedTags).ToList();
                foreach (Tag tagToDelete in tagsToDelete)
                {
                    toastTagRepository.Delete(tt => tt.TagId == tagToDelete.Id && tt.ToastId == existingToast.Id);
                }

                Toast res = await toastRepository.UpdateAsync(existingToast);

                return(res.ToDto());
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                throw;
            }
        }
Esempio n. 3
0
        public void Notify(string title, string message, EToastColor type = EToastColor.InfoColor)
        {
            var dto = new ToastDto
            {
                Title   = title,
                Message = message,
                Color   = type
            };

            _notifier.Notify <CustomNotification>(() => new CustomNotification(dto));
        }
Esempio n. 4
0
        public async Task <OperationDetails> Create(ToastDto toastDto)
        {
            var toast = mapper.Map <ToastDto, Notification>(toastDto);
            await unitOfWork.NotificationRepo.Insert(toast);

            var res = unitOfWork.Save();

            if (res > 0)
            {
                return(new OperationDetails(true, "Saved successfully", ""));
            }
            return(new OperationDetails(true, "Something has gone wrong", ""));
        }
Esempio n. 5
0
        public async Task <ActionResult <ToastDto> > GetRandomToast([FromHeader] List <Guid> tagIds)
        {
            try
            {
                ToastDto res = await dataService.GetRandomToast(tagIds);

                return(Ok(res));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(BadRequest(e.Message));
            }
        }
Esempio n. 6
0
        public async Task <ActionResult> Edit(CreateToastViewModel toastViewModel)
        {
            ToastDto sensorTypeDto = _mapper.Map <CreateToastViewModel, ToastDto>(toastViewModel);
            var      res           = await _toastManager.Update(sensorTypeDto);

            if (res.Succeeded)
            {
                return(RedirectToAction("Index", "Toast", new { sensorId = toastViewModel.SensorId }));
            }
            else
            {
                return(View());
            }
        }
Esempio n. 7
0
        public async Task <OperationDetails> Update(ToastDto toastDto)
        {
            Notification toast = mapper.Map <ToastDto, Notification>(toastDto);

            try
            {
                await unitOfWork.NotificationRepo.Update(toast);

                unitOfWork.Save();
            }
            catch (Exception)
            {
                return(new OperationDetails(false));
            }
            return(new OperationDetails(true));
        }
Esempio n. 8
0
        public ActionResult <ToastDto> CreateNewToast([FromBody] ToastDto toast)
        {
            try
            {
                if (toast == null)
                {
                    return(BadRequest());
                }

                ToastDto res = dataService.Create(toast);
                return(Ok(res));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(BadRequest(e.Message));
            }
        }
Esempio n. 9
0
        public async Task <ActionResult <ToastDto> > UpdateToast(Guid id, [FromBody] ToastDto toastDto)
        {
            try
            {
                if (toastDto == null || (toastDto.Id != id))
                {
                    return(BadRequest());
                }

                ToastDto res = await dataService.UpdateAsync(id, toastDto);

                return(Ok(res));
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
                return(BadRequest(e.Message));
            }
        }
Esempio n. 10
0
        public ToastDto Create(ToastDto entity)
        {
            Toast toast = new Toast()
            {
                Id        = Guid.Empty,
                ToastText = entity.ToastText,
                Reviewed  = false,
            };
            Toast res = toastRepository.Create(toast);

            try
            {
                List <ToastTag> toastTags = new List <ToastTag>();
                foreach (TagDto tagDto in entity.Tags)
                {
                    Tag tag = tagRepository.Get(t => t.Id == tagDto.Id);
                    if (tag == null)
                    {
                        throw new ArgumentException("Ein Tag des Trinkspruches konnte nicht gefunden werden");
                    }

                    ToastTag toastTag = new ToastTag()
                    {
                        TagId   = tag.Id,
                        ToastId = toast.Id
                    };
                    toastTags.Add(toastTag);
                }
                toastTagRepository.CreateRange(toastTags);
                return(res.ToDto());
            }
            catch (Exception e)
            {
                toastRepository.Delete(t => t.Id == toast.Id);
                logger.LogError(e.Message);
                throw;
            }
        }
Esempio n. 11
0
 public CustomNotification(ToastDto dto)
 {
     Title   = dto.Title;
     Message = dto.Message;
     Color   = dto.Color.ToString();
 }