Exemplo n.º 1
0
        public IActionResult AddActivity(UpdateActivityModel post)
        {
            if (post == null)
            {
                //Mesaj gönder
                return(View());
            }

            var user = _applicationDbContext.Users.FirstOrDefault(e => e.Id == _userManager.GetUserId(HttpContext.User));

            if (post.PostName == null || post.PostDesc == null || post.PostDate == new DateTime())
            {
                return(Redirect("/Post"));
            }

            var newPost = new PostModel
            {
                PostName          = post.PostName,
                PostDesc          = post.PostDesc,
                PostDate          = post.PostDate,
                PostTime          = post.PostTime,
                PostCreateTime    = DateTime.Now,
                ApplicationUser   = user,
                ApplicationUserId = user.Id
            };

            _applicationDbContext.Posts.AddAsync(newPost);
            _applicationDbContext.SaveChanges();
            //AddUser
            AddUser(newPost.Id);
            return(Redirect("/Post"));
        }
Exemplo n.º 2
0
        public IActionResult UpdateActivity(int id)
        {
            /*if (!_signInManager.IsSignedIn(HttpContext.User))
             * {
             *  return Redirect("/Account/Login");
             * }*/

            PostModel pModel;

            try
            {
                pModel = _applicationDbContext.Posts.First(p => p.Id == id);
            }
            catch (Exception)
            {
                return(Redirect("/"));
            }

            if (!pModel.ApplicationUserId.Equals(_userManager.GetUserId(HttpContext.User)))
            {
                return(Redirect("/"));
            }

            UpdateActivityModel updateActivityModel = new UpdateActivityModel
            {
                Id       = pModel.Id,
                PostName = pModel.PostName,
                PostDesc = pModel.PostDesc,
                PostDate = pModel.PostDate,
                PostTime = pModel.PostTime
            };

            return(View("UpdateActivity", updateActivityModel));
        }
Exemplo n.º 3
0
        public void Put(Guid id, [FromBody] UpdateActivityModel activity)
        {
            var entity = _repository.GetById(id);

            entity.Update(activity.Name, activity.Description, activity.Type, activity.DashboardId, activity.StartingTime, activity.EndingTime, activity.IsFinished);
            _repository.Edit(entity);
        }
Exemplo n.º 4
0
        public IActionResult UpdateActivity(int id, UpdateActivityModel post)
        {
            if (post != null && post.PostName != null && post.PostDate != null && post.PostTime != null)
            {
            }
            else
            {
                return(Redirect("/Post"));
            }

            PostModel updPost = _applicationDbContext.Posts.First(p => p.Id == id);

            if (updPost == null)
            {
                return(Redirect("/Post"));
            }

            if (!_userManager.GetUserId(User).Equals(updPost.ApplicationUserId))
            {
                return(Redirect("/Post"));
            }

            if (!post.PostName.Equals("") && !post.PostName.Equals(updPost.PostName))
            {
                updPost.PostName = post.PostName;
            }
            if (!post.PostDesc.Equals(updPost.PostName))
            {
                updPost.PostDesc = post.PostDesc;
            }
            if (post.PostDate != null && post.PostDate != new DateTime() && !post.PostDate.Equals(updPost.PostDate))
            {
                updPost.PostDate = post.PostDate;
            }
            if (!(post.PostTime == null) && !post.PostTime.Equals(updPost.PostTime))
            {
                updPost.PostTime = post.PostTime;
            }

            _applicationDbContext.Posts.Update(updPost);
            _applicationDbContext.SaveChanges();
            return(Redirect("/Post"));
        }