示例#1
0
        public async Task <ActionResult> Edit(int id)
        {
            CodeRepository codeRepo;
            CodeView       view = new CodeView()
            {
                Code = new Code()
                {
                    Active = true
                }, CodeCategories = new List <CodeCategory>()
            };

            try
            {
                using (DBConnection dbc = new DBConnection(settings.Database.ConnectionString, logger))
                {
                    codeRepo = new CodeRepository(settings, logger, dbc);

                    view.Code = await codeRepo.FindByPKView(new PrimaryKey()
                    {
                        Key = id, IsIdentity = true
                    });

                    view.CodeCategories = CodeCategory.GetList();
                }
            }
            catch (Exception ex)
            {
                throw (Exception)Activator.CreateInstance(ex.GetType(), ex.Message + ex.StackTrace);
            }

            return(View("Edit", view));
        }
示例#2
0
        public async Task <IActionResult> Edit(int id, [Bind("CategoryId,CategoryName")] CodeCategory codeCategory)
        {
            if (id != codeCategory.CategoryId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(codeCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CodeCategoryExists(codeCategory.CategoryId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(codeCategory));
        }
示例#3
0
        public async Task <ActionResult> Create(CodeView view)
        {
            CodeRepository codeRepo;

            try
            {
                using (DBConnection dbc = new DBConnection(settings.Database.ConnectionString, logger))
                {
                    codeRepo = new CodeRepository(settings, logger, dbc);

                    if (ModelState.IsValid)
                    {
                        await codeRepo.Add(view.Code);

                        return(RedirectToAction("Index", "Code"));
                    }

                    view.CodeCategories = CodeCategory.GetList();
                    return(View("Create", view));
                }
            }
            catch (Exception ex)
            {
                throw (Exception)Activator.CreateInstance(ex.GetType(), ex.Message + ex.StackTrace);
            }
        }
示例#4
0
        public async Task <IActionResult> PutCodeCategory([FromRoute] int id, [FromBody] CodeCategory codeCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != codeCategory.CategoryId)
            {
                return(BadRequest());
            }

            _context.Entry(codeCategory).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CodeCategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#5
0
        public ActionResult Edit(Category entity)
        {
            UserLogin session = (UserLogin)Session[CommonConstants.USER_SESSION];

            try
            {
                if (string.IsNullOrEmpty(entity.Name))
                {
                    return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
                }
                //entity.CreatedBy = session.UserID;
                var model = new CodeCategory();
                model.Update(entity);
                return(Json(new { Success = true }, JsonRequestBehavior.AllowGet));
            }
            catch (DbUpdateException ex)
            {
                ViewBag["Error"] = ex.Message;
                return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ViewBag["Error"] = ex.Message;
                return(Json(new { Success = false }, JsonRequestBehavior.AllowGet));
            }
        }
示例#6
0
        public ActionResult ProductCategory(int id, int page = 1, int pageSize = 4)
        {
            var productcategory = new CodeCategory().ViewDetail(id);

            ViewBag.Category = productcategory;
            int totalRecord = 0;
            var model       = new CodeProduct().ListProductCategory(id, ref totalRecord, page, pageSize);

            //ViewBag.TagPost = new CodePost().ListPostCategory(id);
            ViewBag.Total = totalRecord;
            ViewBag.Page  = page;

            int maxPage   = 4;
            int totalPage = 0;

            totalPage         = (int)Math.Ceiling((double)(totalRecord / pageSize));
            ViewBag.TotalPage = totalPage;
            ViewBag.MaxPage   = maxPage;
            ViewBag.First     = 1;
            ViewBag.Last      = totalPage;
            ViewBag.Next      = page + 1;
            ViewBag.Prev      = page - 1;


            return(View(model));
        }
示例#7
0
        public async Task <VmGenericServiceResult> Update(VmCodeCategoryItem vmCodeCategoryItem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                CodeCategory r = await repo.Get(vmCodeCategoryItem.Id);

                Copy <VmCodeCategoryItem, CodeCategory>(vmCodeCategoryItem, r);

                if (r.UpdatedBy.IsNullOrEmpty())
                {
                    r.UpdatedBy = "System";
                }

                repo.Update(r);

                repo.Commit();

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Error     = e;
            }

            return(result);
        }
示例#8
0
        public async Task Delete(int Id)
        {
            CodeCategory r = await repo.Get(Id);

            r.IsActive = false;
            repo.Update(r);
            repo.Commit();
        }
示例#9
0
        public void SetViewBag(long?ID = null)
        {
            //var model = new CodeCategory();
            //ViewBag.CategoryID = new SelectList(model.ListAll(), "ID", "Name", ID);

            var model = new CodeCategory();
            IEnumerable <SelectListItem> userTypeList = new SelectList(model.ListAll(), "ID", "ID");

            ViewData["CategoryList"] = userTypeList;
        }
示例#10
0
        public async Task <IActionResult> Create([Bind("CategoryId,CategoryName")] CodeCategory codeCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(codeCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(codeCategory));
        }
示例#11
0
        public async Task <IActionResult> PostCodeCategory([FromBody] CodeCategory codeCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.CodeCategory.Add(codeCategory);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCodeCategory", new { id = codeCategory.CategoryId }, codeCategory));
        }
示例#12
0
        // GET: Admin/Category
        public ActionResult Index()
        {
            try
            {
                var model  = new CodeCategory();
                var result = model.ListAllCategory(0);
                return(View(result));
            }
            catch (Exception ex)
            {
                ViewData["Error"] = ex.Message;

                return(View());
            }
        }
示例#13
0
        public async void Task4_Put_Update_Category_NoContentResult()
        {
            //Arrange
            _context    = new SDCContext(dbContextOptions);
            _controller = new CodeCategoriesController(_context);
            int newId = 21;

            //Act
            var category = new CodeCategory()
            {
                CategoryId   = newId,
                CategoryName = "Update Bedding"
            };
            var updatedData = await _controller.PutCodeCategory(newId, category);

            //Assert
            Assert.IsType <NoContentResult>(updatedData);
        }
示例#14
0
        public JsonResult DataTableGet([ModelBinder(typeof(DataTablesBinder))] IDataTablesRequest requestModel)
        {
            var context = new ShopBanHangDbContext();
            var model   = new CodeCategory();
            IQueryable <CategoryModel> query = model.ListAllCategory(0).AsQueryable();

            var totalCount = query.Count();

            // Apply filters
            if (!string.IsNullOrEmpty(requestModel.Search.Value))
            {
                var value = requestModel.Search.Value.Trim();
                query = query.Where(p => p.Name.Contains(value));
            }

            var filteredCount = query.Count();

            // Sort
            var sortedColumns = requestModel.Columns.GetSortedColumns();
            var orderByString = String.Empty;

            foreach (var column in sortedColumns)
            {
                orderByString += orderByString != String.Empty ? "," : "";
                orderByString += (column.Data) + (column.SortDirection == Column.OrderDirection.Ascendant ? " asc" : " desc");
            }

            orderByString = orderByString == String.Empty ? "name asc" : orderByString;
            query         = query.OrderBy(orderByString);

            // Paging
            query = query.Skip(requestModel.Start).Take(requestModel.Length);

            var data = query.Select(p => new
            {
                Id          = p.ID,
                Name        = p.Name,
                CreatedDate = p.CreatedDate.ToString("dd-MM-yyyy"),
                UserName    = p.UserName,
                Action      = "<br /><p class=\"btn-action\"><a href=\"#\" class=\"detail\"><i class=\"ui-tooltip fa fa-pencil-square-o detail\" style=\"font-size: 22px;\" data-original-title=\"Detail\"></i></a> <a href=\"#\" class=\"remove\" ><i class=\"ui-tooltip fa fa-trash-o remove\" style=\"font-size: 20px;\" data-original-title=\"Delete\" tooltip=\"Delete\"></i></a></p>",
            }).ToList();

            return(Json(new DataTablesResponse(requestModel.Draw, data, filteredCount, totalCount), JsonRequestBehavior.AllowGet));
        }
示例#15
0
        private async void Task5_Delete_Category_OkResult()
        {
            //Arrange
            _context    = new SDCContext(dbContextOptions);
            _controller = new CodeCategoriesController(_context);
            var category = new CodeCategory()
            {
                CategoryName = "New and Del Pickle",
            };

            //Act
            var resultCreate = await _controller.PostCodeCategory(category);

            var okResult  = resultCreate.Should().BeOfType <CreatedAtActionResult>().Subject;
            var resClient = okResult.Value.Should().BeAssignableTo <CodeCategory>().Subject;
            int delId     = resClient.CategoryId;
            var result    = await _controller.DeleteCodeCategory(delId);

            //Assert
            Assert.IsType <OkObjectResult>(result);
        }
示例#16
0
        public async Task <ActionResult> Create()
        {
            CodeView view = new CodeView()
            {
                Code = new Code()
                {
                    Active = true
                },
                CodeCategories = new List <CodeCategory>()
            };

            try
            {
                view.CodeCategories = CodeCategory.GetList();
            }
            catch (Exception ex)
            {
                throw (Exception)Activator.CreateInstance(ex.GetType(), ex.Message + ex.StackTrace);
            }

            return(await System.Threading.Tasks.Task.Run(() => View("Create", view)));
        }
示例#17
0
        public VmGenericServiceResult Insert(VmCodeCategoryItem vmCodeCategoryItem)
        {
            VmGenericServiceResult result = new VmGenericServiceResult();

            try
            {
                CodeCategory r = new CodeCategory();

                Copy <VmCodeCategoryItem, CodeCategory>(vmCodeCategoryItem, r);

                if (r.CreatedBy.IsNullOrEmpty())
                {
                    r.CreatedBy = r.UpdatedBy = "System";
                }
                repo.Add(r);

                repo.Commit();

                result.IsSuccess = true;
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                var repoEntity = repo.Get(vmCodeCategoryItem.Id);
                if (repoEntity != null)
                {
                    Exception ee = new Exception("Id is already existed!");

                    result.Error = ee;
                }
                else
                {
                    result.Error = e;
                }
            }

            return(result);
        }
示例#18
0
        public async void Task3_Post_NewCategory_FindName()
        {
            //Arrange
            _context    = new SDCContext(dbContextOptions);
            _controller = new CodeCategoriesController(_context);
            var category = new CodeCategory()
            {
                CategoryName = "NewPickle",
            };

            //Act
            var result = await _controller.PostCodeCategory(category);

            //Assert
            var okResult  = result.Should().BeOfType <CreatedAtActionResult>().Subject;
            var resClient = okResult.Value.Should().BeAssignableTo <CodeCategory>().Subject;

            resClient.CategoryName.Should().Be("NewPickle");

            //delete JayNew
            int newId        = _context.CodeCategory.FirstOrDefault(p => p.CategoryName == "NewPickle").CategoryId;
            var resultDelete = await _controller.DeleteCodeCategory(newId);
        }
示例#19
0
        public void Get()
        {
            CodeCategory codeCategory = DataRepository.CodeCategory.Get(1);

            Assert.AreEqual("패티", codeCategory.Item);
        }
示例#20
0
        public ActionResult Edit(int id)
        {
            var category = new CodeCategory().ViewDetail(id);

            return(View(category));
        }
示例#21
0
        public ActionResult Categories()
        {
            var model = new CodeCategory().ListAll();

            return(View(model));
        }