Exemplo n.º 1
0
        public async Task AddSurveyCategoriesAsync(IEnumerable <string> Names)
        {
            var surveyCategories = await GetSurveyCategoriesAsync(Names);

            if (surveyCategories?.Count() == 0)
            {
                foreach (var Name in Names)
                {
                    var surveyCategory = new SurveyCategory()
                    {
                        Name      = Name,
                        PublicKey = Guid.NewGuid()
                    };

                    try
                    {
                        await context.SurveyCategories
                        .AddAsync(surveyCategory);

                        await context.SaveChangesAsync();

                        log.LogInformation($"added survey category with id='{surveyCategory.Id}', name='{surveyCategory.Name}', " +
                                           $"nameid='{surveyCategory.NameId}', publickey='{surveyCategory.PublicKey}'");
                    }
                    catch (Exception e)
                    {
                        throw new SurveyException(HttpStatusCode.InternalServerError,
                                                  $"couldn't add survey category with name={Name}. error={e.Message}");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            ViewBag.LastThreeSlider = HttpContext.Session["LastThreeSlider"];
            ViewBag.LastThreeSurvey = HttpContext.Session["LastThreeSurvey"];

            int surveyid = Convert.ToInt32(Request.QueryString["surveyid"]);

            if (surveyid != 0)
            {
                FullSurveyVM   fsm  = new FullSurveyVM();
                SurveyCategory post = db.SurveyCategories.FirstOrDefault(x => x.ID == surveyid);
                fsm.SurveyCategory = post;
                fsm.SurveyOption   = post.SurveyOptions;
                if (post != null)
                {
                    HttpContext.Session["SurveyID"] = post.ID;
                    return(View(fsm));
                }
                else
                {
                    return(View());
                }
            }
            else
            {
                return(View());
            }
        }
        public JsonResult DeleteSurvey(int id)
        {
            SurveyCategory survey = db.SurveyCategories.FirstOrDefault(x => x.ID == id);

            survey.IsDeleted = true;
            if (survey.SurveyOptions.Count > 0)
            {
                foreach (var opt in survey.SurveyOptions)
                {
                    opt.IsDeleted  = true;
                    opt.DeleteDate = DateTime.Now;
                }
            }
            survey.DeleteDate = DateTime.Now;
            int result = db.SaveChanges();

            if (result > 0)
            {
                return(Json("1"));
            }
            else
            {
                return(Json("2"));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,CategoryName,SurveyId")] SurveyCategory surveyCategory)
        {
            if (id != surveyCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(surveyCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!SurveyCategoryExists(surveyCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index), new { id = surveyCategory.SurveyId }));
            }
            ViewData["SurveyId"] = new SelectList(_context.Survey, "Id", "Id", surveyCategory.SurveyId);
            return(View(surveyCategory));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("CategoryName,SurveyId")] SurveyCategory surveyCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(surveyCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index), new { id = surveyCategory.SurveyId }));
            }
            ViewData["SurveyId"] = new SelectList(_context.Survey, "Id", "Id", surveyCategory.SurveyId);
            return(View(surveyCategory));
        }
Exemplo n.º 6
0
        public async Task AddSurveyCategoryAsync(string Name)
        {
            var surveyCategory = await GetSurveyCategoryAsync(Name);

            if (surveyCategory == null)
            {
                surveyCategory = new SurveyCategory()
                {
                    Name      = Name,
                    PublicKey = Guid.NewGuid()
                };

                await context.SurveyCategories
                .AddAsync(surveyCategory);

                await context.SaveChangesAsync();
            }
        }
        public async Task <IActionResult> Create([Bind("CategoryName,SurveyId")] SurveyCategory surveyCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(surveyCategory);
                await _context.SaveChangesAsync();

                TempData["FeedbackMessage"] = $"survey category added successfully";
                if (Request.Headers["X-Requested-With"] == "XMLHttpRequest")
                {
                    return(RedirectToAction("_CreatePartial", "SurveySubjects", new { id = surveyCategory.Id }));
                }
                return(RedirectToAction(nameof(Create), "SurveySubjects", new { id = surveyCategory.Id }));
            }

            ViewData["SurveyId"] = new SelectList(_context.Survey, "Id", "Id", surveyCategory.SurveyId);
            return(View(surveyCategory));
        }
        //Listeleme ekranından anket seçildiğinde seçilen anketin bilgileri dolduruluyor.
        public ActionResult UpdateSurvey()
        {
            int                 id      = Convert.ToInt32(Request.QueryString["surveyid"].ToString());
            SurveyCategory      survey  = db.SurveyCategories.FirstOrDefault(x => x.ID == id);
            List <SurveyOption> options = db.SurveyOptions.Where(s => s.SurveyId == id).ToList();
            SurveyWithOptionsVM svm     = new SurveyWithOptionsVM();

            SurveyCategoryVM scvm = new SurveyCategoryVM();

            scvm.Description   = survey.Description;
            scvm.ID            = survey.ID;
            scvm.SurveyName    = survey.SurveyName;
            scvm.SurveyOptions = survey.SurveyOptions;

            svm.SurveyCategoriesVM = scvm;
            svm.SurveyOptionsVM    = new SurveyOptionVM[scvm.SurveyOptions.Count];
            for (int i = 0; i <= scvm.SurveyOptions.Count - 1; i++)
            {
                svm.SurveyOptionsVM[i]             = new SurveyOptionVM();
                svm.SurveyOptionsVM[i].OptionValue = scvm.SurveyOptions[i].OptionValue;
                svm.SurveyOptionsVM[i].SurveyId    = scvm.SurveyOptions[i].SurveyId;
                svm.SurveyOptionsVM[i].ID          = scvm.SurveyOptions[i].ID;
            }

            //güncellenecek kategoriyi ekrana yazdırmak için
            //SurveyCategory model = new SurveyCategory();
            //model.SurveyName = survey.SurveyName;
            //model.Description = survey.Description;

            //return View(model);
            ViewBag.Mode = "Update";
            if (survey != null)
            {
                return(View(svm));
            }
            else
            {
                return(View());
            }
        }
        public ActionResult AddSurvey(SurveyWithOptionsVM model)
        {
            ////SurveyCategoryVM vmodel = new SurveyCategoryVM();

            //if (ModelState.IsValid || (!ModelState.IsValid && model.SurveyCategoriesVM.PostImage == null))
            if (ModelState.IsValid)
            {
                string filename = "";
                foreach (string name in Request.Files)
                {
                    model.SurveyCategoriesVM.PostImage = Request.Files[name];
                    string ext = Path.GetExtension(Request.Files[name].FileName);
                    if (ext == ".jpg" || ext == ".jpeg" || ext == ".png")
                    {
                        string uniqnumber = Guid.NewGuid().ToString();
                        filename = uniqnumber + model.SurveyCategoriesVM.PostImage.FileName;
                        model.SurveyCategoriesVM.PostImage.SaveAs(Server.MapPath("~/Areas/admin/Content/Site/images/addsurvey/" + filename));
                    }
                }

                SurveyCategory post = new SurveyCategory();
                post.SurveyName  = model.SurveyCategoriesVM.SurveyName;
                post.Description = model.SurveyCategoriesVM.Description;
                post.ImagePath   = filename;
                //Eğer ID boş ise ekleme için kullanılır
                //if (model.SurveyCategoriesVM.ID == 0)
                db.SurveyCategories.Add(post);
                //else
                //{//Eğer ID dolu ise bu varolan bir kayıttır vt'den bu kayıt bulunup güncelleme işlemi yapılır.
                //var existedSurvey = db.SurveyCategories.Where(s => s.ID == model.SurveyCategoriesVM.ID).FirstOrDefault();
                ////existedSurvey.ImagePath = model.SurveyCategoriesVM.PostImage.p;
                //existedSurvey.SurveyName = model.SurveyCategoriesVM.SurveyName;
                //existedSurvey.Description = model.SurveyCategoriesVM.Description;
                //}

                int result1 = db.SaveChanges();
                //Seçenekler Ekleniyor
                if (result1 > 0)
                {
                    //if (model.SurveyOptionsVM.Length > 0)
                    //{
                    var optionsList = model.SurveyOptionsVM.Where(s => !string.IsNullOrEmpty(s.OptionValue)).ToList();

                    foreach (var opt in optionsList)
                    {
                        //if (opt.ID == 0)
                        //{
                        SurveyOption sOm = new SurveyOption();
                        sOm.OptionValue    = opt.OptionValue;
                        sOm.SurveyId       = post.ID;
                        sOm.SurveyCategory = post;
                        db.SurveyOptions.Add(sOm);
                        //}
                        //else
                        //{
                        //    var existedOption = db.SurveyOptions.Where(s => s.ID == opt.ID).FirstOrDefault();
                        //    existedOption.OptionValue = opt.OptionValue;
                        //}
                    }
                }

                int result2 = db.SaveChanges();
                if (result2 > 0)
                {
                    Response.Redirect("/admin/AdminResult/AdminSuccessful", true);
                    ViewBag.IslemDurum = 1;
                    return(View());
                }
                else
                {
                    Response.Redirect("/admin/AdminResult/AdminError", true);
                    ViewBag.IslemDurum = 2;
                    return(View());
                }
                //return View();
            }
            else
            {
                Response.Redirect("/admin/AdminResult/AdminError", true);
                ViewBag.IslemDurum = 2;
                return(View());
            }
        }
Exemplo n.º 10
0
 public ActionResult Create(SurveyCategory surveyCategory)
 {
     unitOfWork.SurveyTypes.AddCategory(surveyCategory);
     unitOfWork.SaveChanges();
     return(RedirectToAction("index"));
 }
        public async Task <IHttpActionResult> Get(int id)
        {
            SurveyCategory surveyCategory = await NextSurveyCategory(id);

            return(Ok(surveyCategory));
        }