Exemplo n.º 1
0
        public static QuoteItemExDTO GetDTO(QuoteItem item)
        {
            QuoteItemExDTO dto = new QuoteItemExDTO();

            dto.Id            = item.Id.ToString();
            dto.IsApproved    = item.IsApproved.ToString();
            dto.IsVisible     = item.IsVisible.ToString();
            dto.Author        = item.Author;
            dto.PrimaryText   = item.PrimaryText;
            dto.SecondaryText = item.SecondaryText;
            dto.PostTime      = item.PostTime.ToShortDateString();

            return(dto);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Add(QuoteItemExDTO item)
        {
            try
            {
                var model = Utils.GetItem(item);
                model.PostTime   = DateTime.UtcNow;
                model.IsApproved = true;
                await _repository.Add(model);

                return(RedirectToAction("NewItems", "Home"));
            }
            catch (Exception)
            {
                return(BadRequest(new { Message = "Some errors occured. Please, try agian later." }));
            }
        }
Exemplo n.º 3
0
        public static QuoteItem GetItem(QuoteItemExDTO itemExDTO)
        {
            QuoteItem item = new QuoteItem();

            item.Id            = string.IsNullOrEmpty(itemExDTO.Id)? 0: long.Parse(itemExDTO.Id);
            item.Author        = itemExDTO.Author;
            item.IsApproved    = string.IsNullOrEmpty(itemExDTO.IsApproved)? false : bool.Parse(itemExDTO.IsApproved);
            item.IsVisible     = string.IsNullOrEmpty(itemExDTO.IsVisible)? false : bool.Parse(itemExDTO.IsVisible);
            item.PrimaryText   = itemExDTO.PrimaryText;
            item.SecondaryText = itemExDTO.SecondaryText;
            DateTime dateTime;

            if (DateTime.TryParse(itemExDTO.PostTime, out dateTime))
            {
                item.PostTime = dateTime;
            }

            return(item);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(long id, QuoteItemExDTO model)
        {
            try
            {
                var newItem = Utils.GetItem(model);
                var item    = await _repository.Get(id);

                if (item == null)
                {
                    return(NotFound());
                }
                item.IsApproved = true;
                await _repository.Update(id, newItem);

                return(RedirectToAction("NewItems", "Home"));
            }
            catch (Exception)
            {
                return(BadRequest(new { Message = "Some errors occured. Please, try agian later." }));
            }
        }