public static UpdateConceptViewModel CreateValidWithoutTags()
        {
            var result = new UpdateConceptViewModel
                             {
                                 AuthorId = 15,
                                 Description = "test-edit-concept-description-view-model",
                                 Id = 14,
                                 Tags = null,
                                 Title = "test-edit-concept-title-view-model"
                             };

            return result;
        }
        public static object CreateWithTags()
        {
            var result = new UpdateConceptViewModel
            {
                AuthorId = 15,
                Description = "test-edit-concept-description-view-model",
                Id = 14,
                Tags = "tag;mark;hash",
                Title = "test-edit-concept-title-view-model"
            };

            return result;
        }
Пример #3
0
        private void UpdateSelected(object sender, RoutedEventArgs e)
        {
            var selected = conceptList.SelectedItem as ConceptViewModel;
            var updateConceptViewModel = new UpdateConceptViewModel
            {
                AuthorId = selected.AuthorId,
                Description = selected.Description,
                Id = selected.Id,
                Title = selected.Title
            };

            ClaimsPrincipal notImplementedYet = null;
            this.conceptLogic.UpdateConcept(updateConceptViewModel, notImplementedYet);
        }
Пример #4
0
        private void UpdateSelected(object sender, RoutedEventArgs e)
        {
            var selected = conceptList.SelectedItem as ConceptViewModel;
            var updateConceptViewModel = new UpdateConceptViewModel
                                             {
                                                 AuthorId = selected.AuthorId,
                                                 Description = selected.Description,
                                                 Id = selected.Id,
                                                 Title = selected.Title
                                             };

            var json = JsonConvert.SerializeObject(updateConceptViewModel);
            using (var w = new WebClient())
            {
                w.Headers.Add("Content-Type", "application/json");
                w.UploadString("http://localhost:7397/concept", "PUT", json);
            }
        }
Пример #5
0
        public JsonResult<OperationResult<bool>> Put(UpdateConceptViewModel model)
        {
            OperationResult<bool> operationResult = null;
            if (ModelState.IsValid)
            {
                var currentUser = this.CurrentUser();
                operationResult = this.conceptLogic.UpdateConcept(model, currentUser);
            }
            else
            {
                var errors = ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage).ToList();
                operationResult = new OperationResult<bool>(false, false, errors);
            }

            var result = new JsonResult<OperationResult<bool>>(
                operationResult,
                new JsonSerializerSettings(),
                Encoding.Default,
                this);

            return result;
        }
Пример #6
0
        public OperationResult<bool> UpdateConcept(UpdateConceptViewModel model, ClaimsPrincipal currentUser)
        {
            var idString = currentUser.Claims.First(x => x.Type == ToBeImplementedClaims.IdClaim).Value;
            var idValue = long.Parse(idString);

            OperationResult<bool> result = null;
            if (model.AuthorId != idValue)
            {
                result = new OperationResult<bool>(
                    false,
                    false,
                    "--- you will not edit concept not authored by you ---");
                return result;
            }

            var updateConcept = Mapper.Map<UpdateConcept>(model);
            this.conceptsService.UpdateConcept(updateConcept);
            result = new OperationResult<bool>(true);
            return result;
        }
Пример #7
0
 public ActionResult Edit(UpdateConceptViewModel model)
 {
     if (ModelState.IsValid)
     {
         var currentUser = this.CurrentUser();
         this.conceptLogic.UpdateConcept(model, currentUser);
         return this.RedirectToAction("Details", "Concepts", new { id = model.Id });
     }
     return this.View("Edit", model);
 }