public IHttpActionResult PutCategoryQuestion(int id, CategoryQuestion categoryQuestion)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != categoryQuestion.CategoryQuestionId)
            {
                return(BadRequest());
            }

            db.Entry(categoryQuestion).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryQuestionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #2
0
        public async Task <CategoryQuestion> CreateCategoryQuestion(CategoryQuestion newCategoryQuestion)
        {
            await _unitOfWork.CategoriesQuestion
            .AddAsync(newCategoryQuestion);

            await _unitOfWork.CommitAsync();

            return(newCategoryQuestion);
        }
Example #3
0
        public async Task AddQuestionCategory(CategoryQuestion category)
        {
            var date = DateTime.Now;

            category.CreationDate = date;

            _context.CategoryQuestions.Add(category);

            await _context.SaveChangesAsync();
        }
Example #4
0
 public static int AddCategoryQuestion(CategoryQuestion obj)
 {
     using (var context = MasterDBContext())
     {
         return(context.StoredProcedure("dbo.AddCategoryQuestion")
                .Parameter("Name", obj.Name)
                .Parameter("CreateDate", obj.CreateDate)
                .Parameter("ModifyDate", obj.ModifyDate)
                .Execute());
     }
 }
        public IHttpActionResult GetCategoryQuestion(int id)
        {
            CategoryQuestion categoryQuestion = db.CategoryQuestions.Find(id);

            if (categoryQuestion == null)
            {
                return(NotFound());
            }

            return(Ok(categoryQuestion));
        }
Example #6
0
        public static void UpdateCategory(CategoryQuestion obj)

        {
            using (var context = MasterDBContext())
            {
                context.StoredProcedure("dbo.UpdateCategory")
                .Parameter("Name", obj.Name)
                .Parameter("Id", obj.Id)
                .Parameter("ModifyDate", obj.ModifyDate)
                .Execute();
            }
        }
        public IHttpActionResult PostCategoryQuestion(CategoryQuestion categoryQuestion)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.CategoryQuestions.Add(categoryQuestion);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = categoryQuestion.CategoryQuestionId }, categoryQuestion));
        }
        public IHttpActionResult DeleteCategoryQuestion(int id)
        {
            CategoryQuestion categoryQuestion = db.CategoryQuestions.Find(id);

            if (categoryQuestion == null)
            {
                return(NotFound());
            }

            db.CategoryQuestions.Remove(categoryQuestion);
            db.SaveChanges();

            return(Ok(categoryQuestion));
        }
Example #9
0
        public JsonResult SaveCategory(CategoryQuestionViewModel model)
        {
            Response response;

            try
            {
                using (var db = new KiaGalleryContext())
                {
                    var userId = GetAuthenticatedUserId();
                    if (model.id != null && model.id > 0)
                    {
                        var category = db.CategoryQuestion.Single(x => x.Id == model.id);
                        category.Id           = model.id;
                        category.Order        = model.order;
                        category.Title        = model.title;
                        category.ModifyUserId = userId;
                        category.ModifyDate   = DateTime.Now;
                        category.CreateIp     = Request.UserHostAddress;
                    }
                    else
                    {
                        var item = new CategoryQuestion()
                        {
                            Id           = model.id,
                            Order        = model.order,
                            Title        = model.title,
                            CreateUserId = userId,
                            ModifyUserId = userId,
                            CreateDate   = DateTime.Now,
                            ModifyDate   = DateTime.Now,
                            CreateIp     = Request.UserHostAddress,
                        };
                        db.CategoryQuestion.Add(item);
                    }
                    db.SaveChanges();
                }
                response = new Response()
                {
                    status  = 200,
                    message = "دسته بندی جدید ثبت شد",
                };
            }
            catch (Exception ex)
            {
                response = Core.GetExceptionResponse(ex);
            }
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
        public async Task <bool> CheckIfHasCategory(List <CategoryQuestion> categories, CategoryQuestion category)
        {
            foreach (CategoryQuestion cat in categories)
            {
                if (cat.Category.Id == category.Category.Id)
                {
                    return(await Task.FromResult(false));
                }
            }

            return(await Task.FromResult(true));
        }
Example #11
0
 public void UpdateCategory(CategoryQuestion obj)
 {
     AdminContext.UpdateCategory(obj);
 }
Example #12
0
 public void AddCategoryQuestion(CategoryQuestion obj)
 {
     AdminContext.AddCategoryQuestion(obj);
 }
Example #13
0
 public async Task UpdateCategoryQuestion(CategoryQuestion categoryQuestionToUpdate, CategoryQuestion categoryQuestion)
 {
     categoryQuestionToUpdate.Category = categoryQuestion.Category;
     await _unitOfWork.CommitAsync();
 }
Example #14
0
 public async Task DeleteCategoryQuestion(CategoryQuestion categoryQuestion)
 {
     _unitOfWork.CategoriesQuestion.Remove(categoryQuestion);
     await _unitOfWork.CommitAsync();
 }