Example #1
0
        public IActionResult DeleteSurvey(int surveyId)
        {
            Survey survey = surveyService.GetSurvey(surveyId);

            surveyService.DeleteSurvey(survey);

            return(View("Views/CreateSurvey/DeletedSuccessfully.cshtml"));
        }
        // GET: Surveys/Delete/id
        public async Task <IActionResult> Delete(int id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            surveyService.DeleteSurvey(surveyService.GetSurveyById(id));

            return(RedirectToAction(nameof(Index)));
        }
        // DELETE api/<controller>/5
        public HttpResponseMessage Delete(int id)
        {
            try
            {
                _service.DeleteSurvey(id);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
 public int DeleteUser(User user)
 {
     if (surveyService.GetCountSurveysByUserId(user.Id) != 0)
     {
         List <Survey> surveys = new List <Survey>();
         surveys = surveyService.GetSurveysByUserId(user.Id);
         foreach (var survey in surveys)
         {
             surveyService.DeleteSurvey(survey);
         }
     }
     context.User.Remove(user);
     context.SaveChanges();
     return(0);
 }
Example #5
0
        public async Task <IActionResult> Remove(int id)
        {
            _logger.LogInformation("Performing delete request...");

            var response = await _surveyService.DeleteSurvey(id);

            if (response.Equals(ServiceResponseType.NotFound))
            {
                _logger.LogWarning("Record does not exist. Unable to delete record.");
                return(NotFound());
            }

            _logger.LogInformation("Record updated successfully.");

            return(Ok());
        }
        public ActionResult Delete(int surveyModelId)
        {
            try
            {
                db.DeleteSurvey(surveyModelId);

                if (Request.UrlReferrer != null)
                {
                    return(Redirect(Request.UrlReferrer.AbsoluteUri));
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message, ex);
                return(HttpNotFound());
            }
        }
        public IHttpActionResult DeleteSurvey(int id)
        {
            var userId   = int.Parse(((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == ClaimTypes.NameIdentifier).FirstOrDefault().Value);
            var roleName = ((ClaimsIdentity)User.Identity).Claims.Where(c => c.Type == ClaimTypes.Role).FirstOrDefault().Value;

            try
            {
                var old = surveyService.Get(id);
                if (roleName.Equals("User") && old.UserId != userId)
                {
                    return(Unauthorized());
                }

                surveyService.DeleteSurvey(old);
                unitOfWork.Commit();
            }
            catch (Exception e)
            {
                return(BadRequest());
            }

            return(Ok());
        }
Example #8
0
 public Survey DeleteSurvey(int Id)
 {
     return(surveyService.DeleteSurvey(Id));
 }