Пример #1
0
        public IActionResult EditStory(string projectid, StoryModel model)
        {
            ViewBag.IsLogin = !string.IsNullOrEmpty(cache.GetString("user"));
            if (ViewBag.IsLogin)
            {
                ViewBag.User = JsonConvert.DeserializeObject <AccountModel>(cache.GetString("user"));
            }
            else
            {
                return(RedirectToAction("Login", "Account"));
            }

            var project = projectSvc.GetProject(projectid);
            var feature = featureSvc.GetFeatures(project._id).FirstOrDefault(it => it._id == model.Feature_id);

            if (ModelState.IsValid)
            {
                var isValid = ValidateClosingDate(false, project, feature, model);
                if (!isValid)
                {
                    PrepareDataForDisplay(projectid, model);
                    ViewBag.ProjectId   = project._id;
                    ViewBag.FeatureName = feature.Name;
                    return(View(model));
                }

                if (!string.IsNullOrEmpty(model.BeAssignedMember_id))
                {
                    var memberships = membershipSvc.GetAllProjectMember(projectid);
                    var ranks       = rankSvc.GetAllRank();
                    var member      = ViewBag.User != null?memberships.FirstOrDefault(it => it.Account_id == ViewBag.User._id && !it.RemoveDate.HasValue) : null;

                    var userRank  = (ranks.FirstOrDefault(it => it._id == member.ProjectRank_id));
                    var canAssign = userRank.CanAssign || member.CanAssign;
                    if (canAssign)
                    {
                        model.AssginByMember_id = ViewBag.User._id;
                    }
                }
                else
                {
                    model.AssginByMember_id = string.Empty;
                }
                model.ClosingDate = model.ClosingDate.AddDays(1);

                storySvc.EditStory(model);
                return(RedirectToAction(nameof(StoryDetail), new { projectid = projectid, featureid = model.Feature_id, storyid = model._id }));
            }
            PrepareDataForDisplay(projectid, model);
            ViewBag.ProjectId   = project._id;
            ViewBag.FeatureName = feature.Name;
            return(View(model));
        }