public ActionResult Edit(CommunityTopicViewModel model, int[] uploadedfile)
 {
     if (ModelState.IsValid)
     {
         CommunityTopic ann = communityService.GetTopic(model.ID);
         ann = AutoMapper.Mapper.Map <CommunityTopicViewModel, CommunityTopic>(model, ann);
         if (uploadedfile != null && uploadedfile.Length > 0)
         {
             foreach (int id in uploadedfile)
             {
                 File file = fileService.getFile(id);
                 if (file != null)
                 {
                     ann.AttachmentFiles.Add(file);
                 }
             }
         }
         ann.LastUpdatedDate = DateTime.UtcNow;
         ApplicationUser user = memberService.GetUser(User.Identity.Name);
         ann.AuthorUserID      = user.Id;
         ann.LastUpdatedUserID = user.Id;
         communityService.SaveTopic();
         TempData["ReloadData"] = true;
         return(RedirectToAction("View", new { id = ann.ID }));
     }
     if (uploadedfile != null)
     {
         if (model.AttachmentFiles == null)
         {
             model.AttachmentFiles = new List <File>();
         }
         foreach (var id in uploadedfile)
         {
             File file = fileService.getFile(id);
             if (file != null)
             {
                 model.AttachmentFiles.Add(file);
             }
         }
     }
     return(View(model));
 }
        public JsonResult Delete(int id)
        {
            CommunityTopic item = this.communityService.GetTopic(id);

            if (item == null)
            {
                return(Json(new { status = HttpStatusCode.NoContent }));
            }
            var             adminRole = memberService.GetUserRoles().SingleOrDefault(r => r.Name == MemberRoles.Admin.ToString());
            ApplicationUser currUser  = memberService.GetUser(User.Identity.Name);

            if (item.AuthorUserID == currUser.Id || currUser.Roles.Any(r => r.RoleId == adminRole.Id))
            {
                communityService.DeleteTopic(item);
                communityService.SaveTopic();
                TempData["ReloadData"] = true;
                return(Json(new { status = HttpStatusCode.OK }));
            }
            return(Json(""));
        }
 public ActionResult Create(CommunityTopic model, int[] uploadedfile)
 {
     if (ModelState.IsValid)
     {
         if (uploadedfile != null)
         {
             model.AttachmentFiles = new List <File>();
             foreach (int id in uploadedfile)
             {
                 File file = fileService.getFile(id);
                 if (file != null)
                 {
                     model.AttachmentFiles.Add(file);
                 }
             }
         }
         model.InsertDate      = DateTime.UtcNow;
         model.LastUpdatedDate = DateTime.UtcNow;
         ApplicationUser user = memberService.GetUser(User.Identity.Name);
         model.AuthorUserID      = user.Id;
         model.LastUpdatedUserID = user.Id;
         communityService.CreateTopic(model);
         communityService.SaveTopic();
         TempData["ReloadData"] = true;
         return(RedirectToAction("Index"));
     }
     if (uploadedfile != null)
     {
         model.AttachmentFiles = new List <File>();
         foreach (var id in uploadedfile)
         {
             File file = fileService.getFile(id);
             if (file != null)
             {
                 model.AttachmentFiles.Add(file);
             }
         }
     }
     return(View(model));
 }
示例#4
0
        private List <CommunityTopic> CreateCommunityTopic(ApplicationDbContext context, List <SubMenu> subMenus, List <ApplicationUser> members)
        {
            List <CommunityTopic> communityTopics = new List <CommunityTopic>();

            for (int i = 0; i < 20; i++)
            {
                CommunityTopic communityTopic = new CommunityTopic
                {
                    Title             = "Community Topic title " + i,
                    Content           = "Community Topic content " + 1,
                    InsertDate        = DateTime.Now,
                    LastUpdatedDate   = DateTime.Now,
                    AuthorUserID      = members[4 + (i % 2)].Id,
                    LastUpdatedUserID = members[4 + (i % 2)].Id
                };
                communityTopics.Add(communityTopic);
            }
            communityTopics.ForEach(f => context.CommunityTopics.AddOrUpdate(f));
            context.SaveChanges();

            return(communityTopics);
        }
示例#5
0
 public void DeleteTopic(CommunityTopic topic)
 {
     this.context.CommunityTopics.Remove(topic);
 }
示例#6
0
 public void CreateTopic(CommunityTopic topic)
 {
     this.context.CommunityTopics.Add(topic);
 }
示例#7
0
 public void DeleteTopic(CommunityTopic topic)
 {
     this.context.CommunityTopics.Remove(topic);
 }
示例#8
0
 public void CreateTopic(CommunityTopic topic)
 {
     this.context.CommunityTopics.Add(topic);
 }