using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Microsoft.AspNet.Identity; using Weee.Areas.Certification.ViewModels; using Weee.Models; using Weee.Models.Paramemter; using Weee.Service; using Resources; using Weee.DAL; namespace Weee.Areas.Certification.Controllers { public class CommentController : CertificationControllerBase { protected WeeeLCADataService lcaDataService; protected WeeeCommentDataService commentDataService; public CommentController(WeeeDataContext db ,WeeeLCADataService lcaDataService , WeeeCommentDataService commentDataService) :base(db) { this.lcaDataService = lcaDataService; this.commentDataService = commentDataService; } protected override void Initialize(System.Web.Routing.RequestContext requestContext) { base.Initialize(requestContext); this.lcaDataService.Initialize(User.Identity.GetUserId()); this.commentDataService.Initialize(User.Identity.GetUserId()); } public ActionResult Index(int lcaId, string category) { var commentViewModel = new CommentViewModel(); var lca = lcaDataService.GetLCA(lcaId); commentViewModel.History = lca.Comments.Where(x => x.Category == category && x.IsHistory).ToList(); commentViewModel.CurrentComment = lca.Comments.Where(x => x.Category == category && !x.IsHistory).SingleOrDefault(); if (commentViewModel.CurrentComment == null) commentViewModel.CurrentComment = new Comment() { LCAID = lca.ID, Category = category }; ViewBag.Message = TempData["Message"]; commentViewModel.LcaStatus = lca.Status; return View(commentViewModel); } [HttpPost] public ActionResult Save(CommentViewModel ToBeSave) { this.commentDataService.SaveComment(ToBeSave.CurrentComment); TempData["Message"] = Resource.CommentSaved; return RedirectToAction("Index", new { lcaId = ToBeSave.CurrentComment.LCAID, category = ToBeSave.CurrentComment.Category }); } } }