Ejemplo n.º 1
0
        public override VMSuggestion Select(int id)
        {
            Suggestion row = _models.Include(r => r.Author).Include(s => s.Status).SingleOrDefault(x => x.Id == id);

            if (row != null)
            {
                VMSuggestion vmSuggestion = new VMSuggestion()
                {
                    Id           = row.Id,
                    Title        = row.Title,
                    Description  = row.Description,
                    QuantityVote = row.QuantityVote,
                    CreatedDate  = row.CreatedDate,
                    UpdatedDate  = row.UpdatedDate,
                    Status       = new VMStatus()
                    {
                        Id = row.Status.Id, Description = row.Status.Description
                    },
                    Author = new VMUserSimple()
                    {
                        Id = row.Author.Id, FullName = row.Author.Name + " " + row.Author.LastName
                    }
                };
                return(vmSuggestion);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        public IActionResult Edit([FromBody] VMSuggestion request)
        {
            if (request.IdAuthor != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (_repository.isFullfilled(request.Id))
            {
                return(BadRequest());
            }
            request.UpdatedDate = DateTime.Now;
            VMMessage msj = _repository.Update(request);

            if (msj.IsSuccessful())
            {
                return(Ok("Edited Successfully."));
            }
            else
            {
                return(BadRequest(msj.Text));
            }
        }
Ejemplo n.º 3
0
        public override void TDelete(VMSuggestion viewModel)
        {
            Suggestion model = _models.Find(viewModel.Id);

            model.Deleted = true;
            _models.Attach(model);
            _dataContext.Entry(model).State = EntityState.Modified;
            _dataContext.SaveChanges();
        }
Ejemplo n.º 4
0
        public override void TUpdate(VMSuggestion viewModel)
        {
            Suggestion model = _models.Find(viewModel.Id);

            model.Title       = viewModel.Title;
            model.Description = viewModel.Description;
            model.UpdatedDate = viewModel.UpdatedDate;
            model.StatusId    = viewModel.StatusId;
            _models.Attach(model);
            _dataContext.Entry(model).State = EntityState.Modified;
            _dataContext.SaveChanges();
        }
Ejemplo n.º 5
0
        // get suggestion with the attribute bool alreadyvoted
        public override VMSuggestion Select(VMVote votes, string tenant)
        {
            User       user             = _dataContext.User.Find(votes.UserId);
            Tenants    tenantencontrado = _CRUDManagerTenant.Find(t => t.User.Tenant.URLOrigin == tenant);
            Suggestion row = _models.Include(r => r.Author).Include(s => s.Status).SingleOrDefault(x => x.Id == votes.SuggestionId);

            if (row.Deleted == true)
            {
                return(null);
            }

            if (row != null && row.Author.TenantId == tenantencontrado.Id)
            {
                VMSuggestion vmSuggestion = new VMSuggestion()
                {
                    Id           = row.Id,
                    Title        = row.Title,
                    Description  = row.Description,
                    QuantityVote = row.QuantityVote,
                    CreatedDate  = row.CreatedDate,
                    UpdatedDate  = row.UpdatedDate,
                    Author       = new VMUserSimple()
                    {
                        Id = row.Author.Id, FullName = row.Author.Name + " " + row.Author.LastName
                    },
                    Status = new VMStatus()
                    {
                        Id = row.Status.Id, Description = row.Status.Description
                    },
                    IsVoted = IsVote(votes)
                };

                if (row.StatusId == 1 || row.StatusId == 3)
                {
                    if (user.RoleId == 2 || user.RoleId == 3)
                    {
                        return(vmSuggestion);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(vmSuggestion);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 6
0
        public void Create()
        {
            IRSuggestion r  = new REFSuggestion(new DataContext(TestBaseEF.GetOptionBuilder().Options));
            VMSuggestion vm = new VMSuggestion()
            {
                Title        = "My Test",
                Description  = "My Description",
                CreatedDate  = DateTime.Now,
                UpdatedDate  = DateTime.Now,
                QuantityVote = 0,
                Author       = new VMUserSimple(1)
            };
            VMMessage msj = r.Insert(vm);

            Assert.IsTrue(msj.IsSuccessful());
        }
Ejemplo n.º 7
0
        public IActionResult Create([FromBody] VMSuggestionAdd request)
        {
            //var aud = User.Claims.First(x => x.Value == request.Tenant);
            //if (aud == null)
            //    return Unauthorized();
            int currentstatus;

            if (request.IdAuthor != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (_repository.Moderation(request.IdAuthor) && !_repository.AdminorModerator(request.IdAuthor))
            {
                currentstatus = 1;
            }
            else
            {
                currentstatus = 2;
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            VMSuggestion vm = new VMSuggestion()
            {
                Title        = request.Title.ToUpper(),
                Description  = request.Description,
                CreatedDate  = DateTime.Now,
                UpdatedDate  = DateTime.Now,
                QuantityVote = 0,
                Author       = new VMUserSimple(request.IdAuthor),
                StatusId     = currentstatus
            };
            VMMessage msj = _repository.Insert(vm);

            if (msj.IsSuccessful())
            {
                return(Ok(vm));
            }
            else
            {
                return(BadRequest(msj.Text));
            }
        }
Ejemplo n.º 8
0
        public IActionResult Load(string tenant, int userId, int suggestionId)
        {
            var test = User.Claims.FirstOrDefault(x => x.Value == tenant);


            VMVote vmvote = new VMVote()
            {
                SuggestionId = suggestionId,
                UserId       = userId
            };
            VMSuggestion vm = _repository.Select(vmvote, tenant);

            if (vm == null)
            {
                return(BadRequest("Could not find suggestion."));
            }
            else
            {
                return(Ok(vm));
            }
        }
Ejemplo n.º 9
0
        public override string TInsert(VMSuggestion viewModel)
        {
            Suggestion model = new Suggestion()
            {
                Title        = viewModel.Title,
                Description  = viewModel.Description,
                QuantityVote = viewModel.QuantityVote,
                CreatedDate  = viewModel.CreatedDate,
                UpdatedDate  = viewModel.UpdatedDate,
                Author       = _dataContext.User.Find(viewModel.IdAuthor),
                Status       = _dataContext.Status.Find(viewModel.StatusId)
            };

            _models.Add(model);
            _dataContext.SaveChanges();
            viewModel.Id = model.Id;
            //send email to the moderator of the suggestion created for user

            _dataContext.Database.ExecuteSqlCommand("exec EmailModeratorSuggestion @SuggestioId, @statusId",
                                                    new SqlParameter("@SuggestioId", viewModel.Id),
                                                    new SqlParameter("@statusId", model.Status.Id));
            return(model.Id.ToString());
        }