public async Task <IActionResult> Edit(int id, [Bind("ID,Name,CategoryID,SeoDescription,HtmlDescription,SeoKeywords")] CategorySub categorySub)
        {
            if (id != categorySub.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(categorySub);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CategorySubExists(categorySub.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "ID", categorySub.CategoryID);
            return(View(categorySub));
        }
        public async Task <VerifyRecordResult> DeleteAsync(int id)
        {
            try
            {
                CleanTrackingHelper.Clean <CategorySub>(context);
                CategorySub item = await context.CategorySub
                                   .AsNoTracking()
                                   .FirstOrDefaultAsync(x => x.Id == id);

                if (item == null)
                {
                    return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法刪除紀錄));
                }
                else
                {
                    CleanTrackingHelper.Clean <CategorySub>(context);
                    context.Entry(item).State = EntityState.Deleted;
                    await context.SaveChangesAsync();

                    CleanTrackingHelper.Clean <CategorySub>(context);
                    return(VerifyRecordResultFactory.Build(true));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "刪除記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "刪除記錄發生例外異常", ex));
            }
        }
        public PartialViewResult EditCategorySub(int categorysubId, int categoryId)
        {
            var model = new CategorySub();

            model = CategorySubBusiness.GetCategorySubByCategorySubIdAndCategoryId(categorysubId, categoryId);
            return(PartialView("EditCategorySub", model));
        }
        public PartialViewResult AddCategorySub(int categoryId)
        {
            var categorySub = new CategorySub();

            categorySub.CategoryId = categoryId;
            return(PartialView("AddCategorySub", categorySub));
        }
        public async Task <IActionResult> PutCategorySub([FromRoute] int id, [FromBody] CategorySub categorySub)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != categorySub.ID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #6
0
        async Task 建立派工單分類清單Async()
        {
            List <CategorySub> categorySubs = new List <CategorySub>();
            int cc = 1;

            #region 派工單主分類
            for (int i = 0; i < 20; i++)
            {
                int main         = i;
                var categoryMain = new CategoryMain()
                {
                    Name   = $"派工單主分類{i}",
                    Enable = true,
                };
                await context.CategoryMain.AddAsync(categoryMain);

                await context.SaveChangesAsync();

                categorySubs.Clear();
                for (int j = 0; j < 20; j++)
                {
                    CategorySub categorySub = new CategorySub()
                    {
                        CategoryMainId = categoryMain.Id,
                        Code           = $"{cc:#####}",
                        Enable         = true,
                        Name           = $"派工單次分類 {main}-{j}",
                        OrderNumber    = cc,
                    };
                    categorySubs.Add(categorySub);
                }
                await context.BulkInsertAsync(categorySubs);
            }
            #endregion
        }
        public async Task <VerifyRecordResult> UpdateAsync(CategorySubAdapterModel paraObject)
        {
            try
            {
                CategorySub itemData = Mapper.Map <CategorySub>(paraObject);
                CleanTrackingHelper.Clean <CategorySub>(context);
                CategorySub item = await context.CategorySub
                                   .AsNoTracking()
                                   .FirstOrDefaultAsync(x => x.Id == paraObject.Id);

                if (item == null)
                {
                    return(VerifyRecordResultFactory.Build(false, ErrorMessageEnum.無法修改紀錄));
                }
                else
                {
                    CleanTrackingHelper.Clean <CategorySub>(context);
                    context.Entry(itemData).State = EntityState.Modified;
                    await context.SaveChangesAsync();

                    CleanTrackingHelper.Clean <CategorySub>(context);
                    return(VerifyRecordResultFactory.Build(true));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "修改記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "修改記錄發生例外異常", ex));
            }
        }
Пример #8
0
        public ActionResult DeleteConfirmed(int id)
        {
            CategorySub categorySub = db.CategoriesSub.Find(id);

            db.CategoriesSub.Remove(categorySub);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #9
0
        public void CreateCategorySub(FormCollection form)
        {
            CategorySub categorysub = JsonConvert.DeserializeObject <CategorySub>(form["CategorySubObj"]);

            categorysub.CategorySub_Status = true;
            categorysub.Category           = db.Categories.Find(categorysub.Category_Id);
            db.CategoriesSub.Add(categorysub);
            db.SaveChanges();
        }
Пример #10
0
        public static CategorySubViewModel GetCategorySubByCategorySubIdAndCategoryId(int categorysubId, int categoryId)
        {
            CategorySub categorySub = identityASPdb.CategorySub.Where(x => x.isDelete != true && x.Id == categorysubId && x.CategoryId == categoryId).FirstOrDefault();

            var model = new CategorySubViewModel();

            model.Id          = categorySub.Id;
            model.Description = categorySub.Description;
            model.CategoryId  = categorySub.CategoryId;
            return(model);
        }
Пример #11
0
 public ActionResult Edit([Bind(Include = "CategorySub_Id,Category_Id,CategorySub_Title,CategorySub_Code,CategorySub_Description,CategorySub_Status")] CategorySub categorySub)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categorySub).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Category_Id = new SelectList(db.Categories, "Category_Id", "Category_Title", categorySub.Category_Id);
     return(View(categorySub));
 }
        public async Task <IActionResult> PostCategorySub([FromBody] CategorySub categorySub)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.CategorySubs.Add(categorySub);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetCategorySub", new { id = categorySub.ID }, categorySub));
        }
        public async Task <IActionResult> Create([Bind("ID,Name,CategoryID,SeoDescription,HtmlDescription,SeoKeywords")] CategorySub categorySub)
        {
            if (ModelState.IsValid)
            {
                _context.Add(categorySub);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name", categorySub.CategoryID);
            return(View(categorySub));
        }
        public async Task <CategorySubAdapterModel> GetAsync(int id)
        {
            CategorySub item = await context.CategorySub
                               .AsNoTracking()
                               .Include(x => x.CategoryMain)
                               .FirstOrDefaultAsync(x => x.Id == id);

            CategorySubAdapterModel result = Mapper.Map <CategorySubAdapterModel>(item);

            await OhterDependencyData(result);

            return(result);
        }
Пример #15
0
        // GET: CategoriesSub/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CategorySub categorySub = db.CategoriesSub.Find(id);

            if (categorySub == null)
            {
                return(HttpNotFound());
            }
            return(View(categorySub));
        }
Пример #16
0
        // Details
        public ActionResult SubCategoryDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CategorySub subCategory = db.CategorySub.Find(id);

            if (subCategory == null)
            {
                return(HttpNotFound());
            }
            return(View(subCategory));
        }
Пример #17
0
        // GET: CategoriesSub/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CategorySub categorySub = db.CategoriesSub.Find(id);

            if (categorySub == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Category_Id = new SelectList(db.Categories, "Category_Id", "Category_Title", categorySub.Category_Id);
            return(View(categorySub));
        }
Пример #18
0
        public void UpdateCategorySub(FormCollection form)
        {
            CategorySub categorysub = JsonConvert.DeserializeObject <CategorySub>(form["CategorySubObj"]);
            var         id          = categorysub.CategorySub_Id;
            var         catsub_db   = db.CategoriesSub.Find(id);

            catsub_db.Category_Id             = categorysub.Category_Id;
            catsub_db.Category                = db.Categories.Find(categorysub.Category_Id);
            catsub_db.CategorySub_Title       = categorysub.CategorySub_Title;
            catsub_db.CategorySub_Code        = categorysub.CategorySub_Code;
            catsub_db.CategorySub_Description = categorysub.CategorySub_Description;
            db.Entry(catsub_db).State         = EntityState.Modified;

            db.SaveChanges();
        }
Пример #19
0
        // GET: Admin/CategoryDetails/Create
        public IActionResult Create(int?id)
        {
            ViewData["CategorySubID"] = new SelectList(_context.CategorySubs, "ID", "Name");
            CategoryDetail detail = new CategoryDetail();

            if (id != null)
            {
                CategorySub sub = _context.CategorySubs.Where(s => s.ID == id).Single();
                if (sub != null)
                {
                    detail.CategorySubID = sub.ID;
                    ViewData["SenderID"] = sub.ID;
                }
            }
            return(View(detail));
        }
Пример #20
0
        public void SetTypeValue(Object sender, Object rowObject, Object newValue)
        {
            if (sender is OLVColumn)
            {
                int rowIndex = (int)rowObject;

                string columnName = ((OLVColumn)sender).Name;

                CategorySub sub = this.category.SubCategories[columnName];
                if (sub != null)
                {
                    if (sub.Types.Count > rowIndex)
                    {
                        string name = (string)newValue;
                        if (DomainModel.Types.Update(sub, sub.Types[rowIndex], name))
                        {
                            sub.Types[rowIndex].Name = name;
                        }
                        else
                        {
                            // Do nothing
                        }
                    }
                    else
                    {
                        int         typeId    = -1;
                        CategorySub neighbour = this.category.GetSubByTypesCount(rowIndex);
                        if (neighbour != null)
                        {
                            typeId = neighbour.Types[rowIndex].Id;
                        }

                        GeneralType type = new GeneralType();
                        type.Name = (string)newValue;
                        type.Id   = typeId;

                        if (DomainModel.Types.Insert(this.category, sub, type))
                        {
                            sub.Types.Add(type);
                        }
                    }
                }
            }
            else
            {
            }
        }
        // GET: Admin/CategorySubs/Create
        public IActionResult Create(int?id)
        {
            CategorySub sub      = new CategorySub();
            Category    category = null;

            if (id != null)
            {
                category = _context.Categories.Single(c => c.ID == id);
                if (sub != null)
                {
                    sub.CategoryID       = category.ID;
                    ViewData["SenderID"] = category.ID;
                }
            }
            ViewData["CategoryID"] = new SelectList(_context.Categories, "ID", "Name");

            return(View(sub));
        }
Пример #22
0
        private static void BuildCache()
        {
            classes = new CategoryClassCollection();
            categoriesRepo.LoadAll(classes);

            foreach (Entities.CategoryClass cat in classes)
            {
                foreach (Culture culture in DomainModel.Cultures.GetAll())
                {
                    GeneralTypeCollection types = Types.GetByName(cat.Name, culture);

                    CategorySub sub = new CategorySub();
                    sub.Language = culture;
                    sub.Types    = types;

                    cat.SubCategories.Add(sub);
                }
            }
        }
        public async Task <VerifyRecordResult> AddAsync(CategorySubAdapterModel paraObject)
        {
            try
            {
                CategorySub itemParameter = Mapper.Map <CategorySub>(paraObject);
                CleanTrackingHelper.Clean <CategorySub>(context);
                await context.CategorySub
                .AddAsync(itemParameter);

                await context.SaveChangesAsync();

                CleanTrackingHelper.Clean <CategorySub>(context);
                return(VerifyRecordResultFactory.Build(true));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "新增記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "新增記錄發生例外異常", ex));
            }
        }
Пример #24
0
        public Object GetTypeValue(Object sender, Object rowObject)
        {
            if (sender is OLVColumn)
            {
                int rowIndex = (int)rowObject;

                string columnName = ((OLVColumn)sender).Name;

                CategorySub sub = this.category.SubCategories[columnName];
                if (sub != null && sub.Types.Count > rowIndex)
                {
                    return(sub.Types[rowIndex].Name);
                }
            }
            else
            {
            }

            return(string.Empty);
        }
        public async Task EnableIt(CategorySubAdapterModel paraObject)
        {
            CategorySub itemData = Mapper.Map <CategorySub>(paraObject);

            CleanTrackingHelper.Clean <CategorySub>(context);
            CategorySub item = await context.CategorySub
                               .AsNoTracking()
                               .FirstOrDefaultAsync(x => x.Id == paraObject.Id);

            if (item == null)
            {
            }
            else
            {
                item.Enable = true;
                context.Entry(item).State = EntityState.Modified;
                await context.SaveChangesAsync();

                CleanTrackingHelper.Clean <MenuData>(context);
            }
        }
Пример #26
0
        public static bool DeleteCategorySub(int categorysubId)
        {
            try
            {
                if (categorysubId != 0)
                {
                    CategorySub categorySub = identityASPdb.CategorySub.Where(x => x.Id == categorysubId).FirstOrDefault();

                    categorySub.isDelete = true;                                           //  set flag to true(deleted)
                    identityASPdb.Entry(categorySub).State = EntityState.Modified;
                    identityASPdb.SaveChanges();
                    result = true;
                }
            }
            catch (Exception)
            {
                throw;
            }

            return(result);
        }
Пример #27
0
        // ---------   Save Sub Category   --------- !

        public JsonResult SaveSubCategoryInDatabase(CategorySub model)
        {
            string Msg = null;

            CategorySub subCategory = new CategorySub();

            var SubCategoryName = db.CategorySub.Where(c => c.SubCategoryName == model.SubCategoryName && c.CategoryID == model.CategoryID).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (SubCategoryName == null)
                {
                    if (model.SubCategoryID > 0)
                    {
                        subCategory = db.CategorySub.SingleOrDefault(x => x.SubCategoryID == model.SubCategoryID);
                        subCategory.SubCategoryName = model.SubCategoryName;
                        db.SaveChanges();
                        Msg = "Sub Category Update Successfully";
                    }
                    else
                    {
                        subCategory.SubCategoryName = model.SubCategoryName;
                        subCategory.MainCategoryID  = model.MainCategoryID;
                        subCategory.CategoryID      = model.CategoryID;
                        db.CategorySub.Add(subCategory);
                        db.SaveChanges();
                        Msg = "Sub Category Save Successfully";
                    }
                }
                else
                {
                    Msg = "Item Name already Exists";
                }
            }
            return(Json(Msg, JsonRequestBehavior.AllowGet));
        }
Пример #28
0
        public static bool AddCategorySub(CategorySubViewModel model, out int categorysubId)
        {
            var categorysub = new CategorySub();

            if (model.Id == 0)
            {
                try
                {
                    categorysub.CategoryId  = model.CategoryId;
                    categorysub.Id          = model.Id;
                    categorysub.Description = model.Description;
                    identityASPdb.CategorySub.Add(categorysub);
                    identityASPdb.SaveChanges();
                    result = true;
                }
                catch (Exception)
                {
                    throw;
                }
            }

            categorysubId = categorysub.Id;
            return(result);
        }
Пример #29
0
 public static bool Insert(CategoryClass category, CategorySub sub, GeneralType type)
 {
     return(repo.Insert(category.Id, sub.Language.Id, type));
 }
Пример #30
0
        public static CategorySub GetCategorySubByCategorySubIdAndCategoryId(int categorysubId, int categoryId)
        {
            CategorySub categorySub = identityASPdb.CategorySub.Where(x => x.Id == categorysubId && x.CategoryId == categoryId && x.isDelete != true).FirstOrDefault();

            return(categorySub);
        }