public async void TestSaveNotExistingCategoryWithNotExistingId()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            HomeMyDayDbContext context = new HomeMyDayDbContext(optionsBuilder.Options);

            FaqCategory ExistingCat = new FaqCategory()
            {
                Id           = 1,
                CategoryName = "Test",
            };

            await context.FaqCategory.AddAsync(ExistingCat);

            await context.SaveChangesAsync();

            IFaqRepository repository = new EFFaqRepository(context);

            // Change some values
            FaqCategory catToUpdate = new FaqCategory()
            {
                Id           = 2,
                CategoryName = "New",
            };

            await Assert.ThrowsAsync <DbUpdateConcurrencyException>(() => repository.SaveCategory(catToUpdate));
        }
        public async void TestSaveUpdatedCategory()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            HomeMyDayDbContext context = new HomeMyDayDbContext(optionsBuilder.Options);

            FaqCategory catToUpdate = new FaqCategory()
            {
                Id           = 1,
                CategoryName = "Test",
            };

            await context.FaqCategory.AddAsync(catToUpdate);

            await context.SaveChangesAsync();

            IFaqRepository repository = new EFFaqRepository(context);

            // Change some values
            catToUpdate.CategoryName = "New";

            await repository.SaveCategory(catToUpdate);

            // Check if the item was updated
            FaqCategory updatedCat = await context.FaqCategory.FindAsync((long)1);

            Assert.NotNull(updatedCat);
            Assert.Equal("New", updatedCat.CategoryName);
        }
示例#3
0
        public List <Faq> SelectAll()
        {
            List <Faq> listFaq = new List <Faq>();
            Faq        faq     = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Faq_SelectAll",
                                    inputParamMapper : null
                                    , map : delegate(IDataReader reader, short set)
            {
                faq = new Faq();
                int startingIndex = 0;       //startingOrdinal

                faq.Id            = reader.GetInt32(startingIndex++);
                faq.DateCreated   = reader.GetDateTime(startingIndex++);
                faq.DateModified  = reader.GetDateTime(startingIndex++);
                faq.UserIdCreated = reader.GetString(startingIndex++);
                faq.Question      = reader.GetString(startingIndex++);
                faq.Answer        = reader.GetString(startingIndex++);
                FaqCategory fc    = new FaqCategory();
                fc.Id             = reader.GetSafeInt32(startingIndex++);
                fc.Name           = reader.GetSafeString(startingIndex++);
                faq.FaqCategory   = fc;

                if (faq == null)
                {
                    listFaq = new List <Faq>();
                }

                listFaq.Add(faq);
            }
                                    );

            return(listFaq);
        }
        public async void TestDeleteFaqCategoryCalled()
        {
            FaqCategory cat = new FaqCategory {
                Id = 1, CategoryName = "Test"
            };

            Mock <IFaqRepository> mock = new Mock <IFaqRepository>();

            mock.Setup(m => m.GetCategoriesAndQuestions()).Returns(new FaqCategory[] {
                new FaqCategory {
                    Id = 1, CategoryName = "Test2"
                }, cat, new FaqCategory {
                    Id = 3, CategoryName = "Test33"
                },
            });

            IFaqManager manager = new FaqManager(mock.Object);

            FaqController target = new FaqController(manager);
            //try to delete
            await target.DeleteCategory(cat.Id);

            //Check if DeleteCategory is called
            mock.Verify(m => m.DeleteCategory(cat.Id));
        }
示例#5
0
        public Faq SelectById(int id)
        {
            Faq faq = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.Faq_SelectById",
                                    inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Id", id);
            }
                                    , map : delegate(IDataReader reader, short set)
            {
                faq = new Faq();
                int startingIndex = 0;

                faq.Id            = reader.GetInt32(startingIndex++);
                faq.DateCreated   = reader.GetDateTime(startingIndex++);
                faq.DateModified  = reader.GetDateTime(startingIndex++);
                faq.UserIdCreated = reader.GetString(startingIndex++);
                faq.Question      = reader.GetString(startingIndex++);
                faq.Answer        = reader.GetString(startingIndex++);
                FaqCategory fc    = new FaqCategory();
                fc.Id             = reader.GetSafeInt32(startingIndex++);
                fc.Name           = reader.GetSafeString(startingIndex++);
                faq.FaqCategory   = fc;
            }
                                    );
            return(faq);
        }
示例#6
0
        public void FaqCategoryService_Delete()
        {
            IFaqCategoryService service = this.GetService <IFaqCategoryService>();
            FaqCategory         result  = service.GetById(7);

            Assert.IsNotNull(result, "We a null value");
        }
示例#7
0
        protected FaqCategoryViewModel ToViewModel(FaqCategory category)
        {
            FaqCategoryViewModel vm = Mapper.Map <FaqCategoryViewModel>(category);

            vm.Items = category.FaqItems.Select(ToViewModel);
            return(vm);
        }
示例#8
0
        public List <FaqCategory> GetCategories()
        {
            List <FaqCategory> list     = null;
            string             procName = "[dbo].[Faq_Categories_SelectAll]";

            _data.ExecuteCmd(procName, inputParamMapper : null
                             , singleRecordMapper : delegate(IDataReader reader, short set)
            {
                FaqCategory aFaq = new FaqCategory();

                int startingIndex = 0;

                aFaq.Id   = reader.GetSafeInt32(startingIndex++);
                aFaq.Name = reader.GetSafeString(startingIndex++);


                if (list == null)
                {
                    list = new List <FaqCategory>();
                }
                list.Add(aFaq);
            });


            return(list);
        }
        public async void TestSaveNewCategory()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            HomeMyDayDbContext context = new HomeMyDayDbContext(optionsBuilder.Options);

            context.FaqCategory.AddRange(
                new FaqCategory()
            {
                CategoryName = "Test"
            }
                );

            await context.SaveChangesAsync();

            IFaqRepository repository = new EFFaqRepository(context);

            FaqCategory categoryToCreate = new FaqCategory()
            {
                CategoryName = "Test"
            };

            await repository.SaveCategory(categoryToCreate);

            // Check if the item was created
            FaqCategory foundCat = await context.FaqCategory.FirstOrDefaultAsync(x => x.CategoryName == "Test");

            Assert.NotNull(foundCat);
            Assert.Equal("Test", foundCat.CategoryName);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            FaqCategory faqCategory = db.FaqCategories.Find(id);

            db.FaqCategories.Remove(faqCategory);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Delete(int id)
        {
            FaqCategory category = db.FaqCategories.Find(id);

            db.FaqCategories.Remove(category);
            db.SaveChanges();
            return(RedirectToAction("List"));
        }
        public ActionResult Update(int id, String UpdatedFaqCatName)
        {
            FaqCategory category = db.FaqCategories.Find(id);

            category.FaqCatName = UpdatedFaqCatName;
            db.SaveChanges();
            return(RedirectToAction("List"));
        }
 public ActionResult Edit([Bind(Include = "Id,Name")] FaqCategory faqCategory)
 {
     if (ModelState.IsValid)
     {
         db.Entry(faqCategory).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(faqCategory));
 }
 protected FaqCategoryDetails ToDetailsModel(FaqCategory category)
 {
     return(new FaqCategoryDetails
     {
         Id = category.Id,
         Name = category.Name,
         IsPublished = category.IsPublished,
         ItemsCount = category.FaqItems?.Count ?? 0
     });
 }
        protected override void OnHandling(AddFaqCategoryCommand command, CommandResult result)
        {
            FaqCategory category = new FaqCategory
            {
                Name        = command.CategoryName,
                IsPublished = command.IsPublished
            };

            DataContext.FaqCategories.Add(category);
        }
        public ActionResult Add(String newFaqCatName)
        {
            FaqCategory category = new FaqCategory()
            {
                FaqCatName = newFaqCatName
            };

            db.FaqCategories.Add(category);
            db.SaveChanges();
            return(Redirect("/Faq/Add"));
        }
        public ActionResult Create([Bind(Include = "Id,Name")] FaqCategory faqCategory)
        {
            if (ModelState.IsValid)
            {
                db.FaqCategories.Add(faqCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(faqCategory));
        }
        public async Task <IActionResult> AddFaqCategory([FromBody] FaqCategory faqCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.FaqCategories.Add(faqCategory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFaqCategory", new { id = faqCategory.Id }, faqCategory));
        }
        protected override FindFaqCategoryByIdQueryResult OnExecuting(IdCriterion criterion)
        {
            FaqCategory category = DataContext.FaqCategories.Find(criterion.Id);

            FindFaqCategoryByIdQueryResult result = new FindFaqCategoryByIdQueryResult
            {
                Category        = category,
                IsFoundCategory = category != null
            };

            return(result);
        }
        public async Task <IActionResult> EditCategory(FaqCategory cat)
        {
            if (ModelState.IsValid)
            {
                await _faqManager.SaveCategory(cat);

                return(RedirectToAction(
                           actionName: nameof(Index),
                           controllerName: nameof(FaqController).TrimControllerName()));
            }

            return(View(cat));
        }
示例#21
0
        public HttpResponseMessage SelectById(int id)
        {
            try
            {
                FaqCategory faqCategory = _faqCategoryService.SelectById(id);
                return(Request.CreateResponse(HttpStatusCode.OK, faqCategory));
            }

            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
        public List <FaqCategory> Get()
        {
            List <FaqCategory> list = new List <FaqCategory>();

            this.DataProvider.ExecuteCmd("dbo.FaqCategory_GetAll"
                                         , inputParamMapper : null
                                         , singleRecordMapper : delegate(IDataReader reader, short set)
            {
                FaqCategory singleItem = Mapper(reader);
                list.Add(singleItem);
            });
            return(list);
        }
        public IActionResult Post([FromBody] FaqCategory faqCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            faqManager.SaveCategory(faqCategory);

            return(CreatedAtAction(nameof(Get), new { id = faqCategory.Id }, new HALResponse(faqCategory).AddLinks(new Link[] {
                new Link(Link.RelForSelf, $"api/v1/faq/categories/{faqCategory.Id}")
            })));
        }
示例#24
0
        public JsonResult Save(FaqCategoryViewModel model)
        {
            var currentUser = GetAuthenticatedUser();

            try
            {
                if (string.IsNullOrEmpty(model.title))
                {
                    return(Error("وارد کردن نام دسته بندی اجباری است."));
                }

                if (model.id != null && model.id > 0)
                {
                    var entity = _context.FaqCategory.Single(x => x.StatusId != FaqCategoryStatus.Deleted.Id && x.Id == model.id);
                    entity.Title        = model.title.ToStandardPersian();
                    entity.Order        = model.order;
                    entity.StatusId     = model.statusId;
                    entity.ModifyUserId = currentUser.id;
                    entity.ModifyDate   = GetDatetime();
                    entity.ModifyIp     = GetCurrentIp();

                    _context.SaveChanges();

                    return(Success("اطلاعات دسته بندی با موفقیت ویرایش شد."));
                }
                else
                {
                    var entity = new FaqCategory()
                    {
                        Title        = model.title.ToStandardPersian(),
                        Order        = model.order,
                        StatusId     = model.statusId,
                        CreateUserId = currentUser.id,
                        ModifyUserId = currentUser.id,
                        CreateDate   = GetDatetime(),
                        ModifyDate   = GetDatetime(),
                        CreateIp     = GetCurrentIp(),
                        ModifyIp     = GetCurrentIp()
                    };

                    _context.FaqCategory.Add(entity);
                    _context.SaveChanges();

                    return(Success("دسته بندی با موفقیت ایجاد شد."));
                }
            }
            catch (Exception ex)
            {
                return(ServerError(ex));
            }
        }
示例#25
0
        protected override void OnHandling(UnpublishFaqCategoryCommand command, CommandResult result)
        {
            FaqCategory category = DataContext.FaqCategories.Find(command.Id);

            if (category == null)
            {
                result.ResultCode = CommandResultCode.Cancelled;
                return;
            }

            category.IsPublished = false;

            DataContext.Entry(category).State = EntityState.Modified;
        }
        // GET: AdminPanel/FaqCategories/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FaqCategory faqCategory = db.FaqCategories.Find(id);

            if (faqCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(faqCategory));
        }
        private FaqCategory Mapper(IDataReader reader)
        {
            FaqCategory singleItem    = new FaqCategory();
            int         startingIndex = 0; //startingOrdinal

            singleItem.Id           = reader.GetSafeInt32(startingIndex++);
            singleItem.DisplayName  = reader.GetSafeString(startingIndex++);
            singleItem.Description  = reader.GetSafeString(startingIndex++);
            singleItem.CreatedDate  = reader.GetSafeDateTime(startingIndex++);
            singleItem.ModifiedDate = reader.GetSafeDateTime(startingIndex++);
            singleItem.ModifiedBy   = reader.GetSafeString(startingIndex++);

            return(singleItem);
        }
示例#28
0
 public Guid UpsertFaqCategory(FaqCategory category)
 {
     using (var command = Context.Connection.GenerateCommand(
                "ais.upsert_faqcategory",
                category,
                new Dictionary <string, object>
     {
         { "planguageid", category.Names.Keys.Select(Guid.Parse).ToArray() },
         { "pname", category.Names.Values }
     }))
     {
         command.ExecuteNonQuerySafety();
         return((Guid)command.Parameters["pid"].Value);
     }
 }
示例#29
0
        public FaqCategory GetFaqCategory(long id)
        {
            FaqCategory category;

            if (id <= 0)
            {
                category = new FaqCategory();
            }
            else
            {
                category = _faqRepository.GetCategory(id);
            }

            return(category);
        }
        public FaqCategory GetById(int Id)
        {
            FaqCategory singleItem = new FaqCategory();

            DataProvider.ExecuteCmd("dbo.FaqCategory_GetById"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Id", Id);
            }
                                    , singleRecordMapper : delegate(IDataReader reader, short set)
            {
                singleItem = Mapper(reader);
            });
            return(singleItem);
        }