Example #1
0
        public IActionResult Update(string id, UpdateFormModel formModel)
        {
            bool updateSuccessful = false;

            var  personToBeUpdated = Repository.GetById(id);
            bool personFound       = (personToBeUpdated != null);

            if (personFound && formModel.NewName.IsNotEmpty())
            {
                personToBeUpdated.Name = formModel.NewName;
                Repository.Update(personToBeUpdated, out updateSuccessful);
            }

            if (updateSuccessful)
            {
                return(RedirectToAction("Index"));
            }
            else if (!personFound)
            {
                return(NotFound());
            }
            else
            {
                return(BadRequest());
            }
        }
Example #2
0
        public async Task <IActionResult> UpdateForm(UpdateFormModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                //update form
                var form = await _tenantRepository.GetFormById(model.FormId, TenantId);

                if (form == null)
                {
                    return(NotFound());
                }
                form.FormJson = model.FormJson.ToString();
                await _tenantRepository.UpdateFormAsync(form, TenantId);

                return(Ok(new { id = form.Id, form_title = form.Title }));
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
Example #3
0
        public ActionResult EditUpdate(int id)
        {
            var             update     = updateService.GetUpdate(id);
            UpdateFormModel editUpdate = Mapper.Map <Update, UpdateFormModel>(update);

            if (update == null)
            {
                return(HttpNotFound());
            }
            return(PartialView("_EditUpdate", editUpdate));
        }
        public ActionResult SaveUpdate(UpdateFormModel newupdate)
        {
            // Update update = Mapper.Map<UpdateFormModel, Update>(newupdate);
            if (ModelState.IsValid)
            {
                Update update = Mapper.Map <UpdateFormModel, Update>(newupdate);
                update.Goal = goalService.GetGoal(newupdate.GoalId);
                var updateVal = updateService.GetHighestUpdateValue(newupdate.GoalId);

                if (updateVal != null)
                {
                    if (updateVal.status <= newupdate.status)
                    {
                        updateService.CreateUpdate(update);
                    }
                    else
                    {
                        update.status = -1;
                        ModelState.AddModelError(update.Updatemsg, "cannot enter");
                    }
                }
                else
                {
                    updateService.CreateUpdate(update);
                }


                var Updates = Mapper.Map <IEnumerable <Update>, IEnumerable <UpdateViewModel> >(updateService.GetUpdatesByGoal(newupdate.GoalId));
                foreach (var item in Updates)
                {
                    item.IsSupported = updateSupportService.IsUpdateSupported(item.UpdateId, User.Identity.GetUserId());
                }
                UpdateListViewModel updates = new UpdateListViewModel()
                {
                    Updates = Updates,
                    Metric  = goalService.GetGoal(newupdate.GoalId).Metric,
                    Target  = goalService.GetGoal(newupdate.GoalId).Target,
                    //IsSupported = updateSupportService.IsUpdateSupported(newupdate.UpdateId,((SocialGoalUser)(User.Identity)).UserId)
                };
                return(PartialView("_UpdateView", updates));
            }
            return(null);
        }
Example #5
0
        public IActionResult UpdateForm(int id, string kindEvent, [FromBody] UpdateFormModel model)
        {
            // map model to entity and set id
            var formEvent = _mapper.Map <EventForm>(model);

            formEvent.EventID = id;

            try
            {
                // update user
                _formEventService.UpdateFormEvent(formEvent, kindEvent);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message.ToString() }));
            }
        }
Example #6
0
        public ActionResult EditUpdate(UpdateFormModel newupdate)
        {
            Update update = Mapper.Map <UpdateFormModel, Update>(newupdate);

            if (ModelState.IsValid)
            {
                update.Goal = goalService.GetGoal(newupdate.GoalId);
                updateService.EditUpdate(update);
                var Updates = Mapper.Map <IEnumerable <Update>, IEnumerable <UpdateViewModel> >(updateService.GetUpdatesByGoal(newupdate.GoalId));
                foreach (var item in Updates)
                {
                    item.IsSupported = updateSupportService.IsUpdateSupported(item.UpdateId, User.Identity.GetUserId());
                }
                UpdateListViewModel updates = new UpdateListViewModel()
                {
                    Updates = Updates,
                    Metric  = goalService.GetGoal(newupdate.GoalId).Metric,
                    Target  = goalService.GetGoal(newupdate.GoalId).Target
                };
                return(PartialView("_UpdateView", updates));
            }
            return(null);
        }