Esempio n. 1
0
        //--------- Save Main Category --------- !

        public JsonResult SaveMainCategoryInDatabase(CategoryMain model)
        {
            string Msg = null;

            CategoryMain mainCategory = new CategoryMain();

            var mainCategoryName = db.CategoryMain.Where(c => c.MaincategoryName == model.MaincategoryName).FirstOrDefault();

            if (ModelState.IsValid)
            {
                if (mainCategoryName == null)
                {
                    if (model.MainCategoryID > 0)
                    {
                        mainCategory = db.CategoryMain.SingleOrDefault(x => x.MainCategoryID == model.MainCategoryID);
                        mainCategory.MaincategoryName = model.MaincategoryName;
                        db.SaveChanges();
                        Msg = "Item Update Successfully";
                    }
                    else
                    {
                        mainCategory.MaincategoryName = model.MaincategoryName;
                        db.CategoryMain.Add(mainCategory);
                        db.SaveChanges();
                        Msg = "Main Category Save Successfully";
                    }
                }
                else
                {
                    Msg = "Item Name already Exists";
                }
            }
            return(Json(Msg, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
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
        }
        /// <summary>
        /// function that create view for category main
        /// </summary>
        /// <param name="uid">user id</param>
        /// <param name="pid">project id</param>
        /// <returns>returns updated model to show in the view</returns>
        public CategoryMain CatView(string uid, int?pid)
        {
            List <category>  CatList = new List <category>();
            ReviseDBEntities con     = new ReviseDBEntities();
            var prjcat = con.projCats.Where(p => p.projId == pid).ToList();

            foreach (var cat in con.categories)
            {
                foreach (var prj in prjcat)
                {
                    if (prj.catId == cat.CatId)
                    {
                        CatList.Add(cat);
                    }
                }
            }
            int roleNum = 7;

            if (con.projUsers.Where(u => u.userid == uid).SingleOrDefault(p => p.projid == pid) != null)
            {
                roleNum = con.projUsers.Where(u => u.userid == uid).SingleOrDefault(p => p.projid == pid).role ?? 7;
            }

            var ShowView = new CategoryMain()
            {
                Cat  = CatList,
                role = roleNum
            };

            return(ShowView);
        }
Esempio n. 4
0
        public async Task <VerifyRecordResult> DeleteAsync(int id)
        {
            try
            {
                CleanTrackingHelper.Clean <CategoryMain>(context);
                CategoryMain item = await context.CategoryMain
                                    .AsNoTracking()
                                    .FirstOrDefaultAsync(x => x.Id == id);

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

                    CleanTrackingHelper.Clean <CategoryMain>(context);
                    return(VerifyRecordResultFactory.Build(true));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "刪除記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "刪除記錄發生例外異常", ex));
            }
        }
Esempio n. 5
0
        public async Task <VerifyRecordResult> UpdateAsync(CategoryMainAdapterModel paraObject)
        {
            try
            {
                CategoryMain itemData = Mapper.Map <CategoryMain>(paraObject);
                CleanTrackingHelper.Clean <CategoryMain>(context);
                CategoryMain item = await context.CategoryMain
                                    .AsNoTracking()
                                    .FirstOrDefaultAsync(x => x.Id == paraObject.Id);

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

                    CleanTrackingHelper.Clean <CategoryMain>(context);
                    return(VerifyRecordResultFactory.Build(true));
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "修改記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "修改記錄發生例外異常", ex));
            }
        }
Esempio n. 6
0
        public async Task <CategoryMainAdapterModel> GetAsync(int id)
        {
            CategoryMain item = await context.CategoryMain
                                .AsNoTracking()
                                .FirstOrDefaultAsync(x => x.Id == id);

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

            await OhterDependencyData(result);

            return(result);
        }
Esempio n. 7
0
        // Edit
        public ActionResult MainCategoryEdit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CategoryMain categorymain = db.CategoryMain.Find(id);

            if (categorymain == null)
            {
                return(HttpNotFound());
            }
            return(View(categorymain));
        }
Esempio n. 8
0
 public CategoryMainDto get(string id)
 {
     try
     {
         CategoryMain categoryMain = _context.CategoryMain.Find(id);
         _context.Entry(categoryMain).Reference(b => b.Category).Load();
         //          _context.Entry(categoryMain).Reference(b => b.Province).Load();
         return(mapper.Map <CategoryMain, CategoryMainDto>(categoryMain));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 9
0
        public async Task EnableIt(CategoryMainAdapterModel paraObject)
        {
            await Task.Delay(100);

            CategoryMain curritem = await context.CategoryMain
                                    .AsNoTracking()
                                    .FirstOrDefaultAsync(x => x.Id == paraObject.Id);

            CleanTrackingHelper.Clean <CategoryMain>(context);
            curritem.Enable = true;
            context.Entry(curritem).State = EntityState.Modified;
            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <CategoryMain>(context);
            return;
        }
Esempio n. 10
0
        public string create(CategoryMainDto tCategoryMainDto)
        {
            try
            {
                CategoryMain tCategoryMainNew = mapper.Map <CategoryMainDto, CategoryMain>(tCategoryMainDto);
                tCategoryMainNew.Id         = Guid.NewGuid().ToString();
                tCategoryMainNew.CreateDate = DateTime.Now;

                _context.CategoryMain.Add(tCategoryMainNew);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
Esempio n. 11
0
        public string delete(string id)
        {
            try
            {
                CategoryMain tCategoryMainRemove = _context.CategoryMain.Find(id);
                if (tCategoryMainRemove == null)
                {
                    return("1");
                }

                _context.CategoryMain.Remove(tCategoryMainRemove);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
Esempio n. 12
0
        public string lockItem(string id)
        {
            try
            {
                CategoryMain tCategoryMainBlock = _context.CategoryMain.Find(id);
                if (tCategoryMainBlock == null)
                {
                    return("1");
                }
                tCategoryMainBlock.Status = false;

                _context.CategoryMain.Update(tCategoryMainBlock);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
Esempio n. 13
0
        public async Task <VerifyRecordResult> AddAsync(CategoryMainAdapterModel paraObject)
        {
            try
            {
                CleanTrackingHelper.Clean <CategoryMain>(context);
                CategoryMain itemParameter = Mapper.Map <CategoryMain>(paraObject);
                CleanTrackingHelper.Clean <CategoryMain>(context);
                await context.CategoryMain
                .AddAsync(itemParameter);

                await context.SaveChangesAsync();

                CleanTrackingHelper.Clean <CategoryMain>(context);
                return(VerifyRecordResultFactory.Build(true));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "新增記錄發生例外異常");
                return(VerifyRecordResultFactory.Build(false, "新增記錄發生例外異常", ex));
            }
        }
Esempio n. 14
0
        //Update
        public string update(CategoryMainDto tCategoryMainDto)
        {
            try
            {
                CategoryMain tCategoryMainUpdate = _context.CategoryMain.Find(tCategoryMainDto.Id);
                if (tCategoryMainUpdate == null)
                {
                    return("1");
                }
                tCategoryMainUpdate.Name       = tCategoryMainDto.Name;
                tCategoryMainUpdate.Name       = tCategoryMainDto.Name;
                tCategoryMainUpdate.Status     = tCategoryMainDto.Status;
                tCategoryMainUpdate.CreateDate = tCategoryMainDto.CreateDate;
                tCategoryMainUpdate.CreateUser = tCategoryMainDto.CreateUser;

                _context.CategoryMain.Update(tCategoryMainUpdate);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception ex)
            {
                return("1");
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Allows custom logic to be applied when switching between categories.
        /// </summary>
        /// <param name="categoryRows">The <see cref="CategoryRow"/> controls.</param>
        /// <param name="changedRow">The changed category row index in the array.</param>
        /// <param name="previous">The previously selected category index.</param>
        /// <param name="current">The newly selected category index.</param>
        protected override void UpdateCategories(CategoryRow[] categoryRows, int changedRow, int previous, int current)
        {
            CategoryRow crMain      = categoryRows[0];
            CategoryRow crSecondary = categoryRows[1];

            if (changedRow == 0)
            {
                // Update the main categories.
                bool         fileOpen         = BinFile != null;
                CategoryMain category         = (CategoryMain)current;
                CategoryMain categoryPrevious = (CategoryMain)previous;

                crMain.ClearCategories();
                crMain.AddCategory("File");
                crMain.AddCategory("Points", fileOpen);
                crMain.AddCategory("Physics", fileOpen);
                crMain.AddCategory("Speed", fileOpen);
                crMain.AddCategory("Handling", fileOpen);

                // Update the secondary categories.
                crSecondary.Visible = category != CategoryMain.File;
                crSecondary.ClearCategories();
                switch (category)
                {
                case CategoryMain.Points:
                    crSecondary.AddCategory("Drivers");
                    crSecondary.AddCategory("Karts");
                    crSecondary.AddCategory("Tires");
                    crSecondary.AddCategory("Gliders");
                    crSecondary.SelectedCategory = _categoryPoints;
                    break;

                case CategoryMain.Physics:
                    crSecondary.AddCategory("Weight");
                    crSecondary.AddCategory("Acceleration");
                    crSecondary.AddCategory("On-Road Slip");
                    crSecondary.AddCategory("Off-Road Slip");
                    crSecondary.AddCategory("Off-Road Brake");
                    crSecondary.AddCategory("Turbo");
                    crSecondary.SelectedCategory = _categoryPhysics;
                    break;

                case CategoryMain.Speed:
                case CategoryMain.Handling:
                    crSecondary.AddCategory("Ground");
                    crSecondary.AddCategory("Water");
                    crSecondary.AddCategory("Anti-Gravity");
                    crSecondary.AddCategory("Gliding");
                    crSecondary.SelectedCategory = _categorySpeedHandling;
                    break;
                }
            }
            else
            {
                // Remember the newly selected secondary category.
                switch ((CategoryMain)crMain.SelectedCategory)
                {
                case CategoryMain.Points:
                    _categoryPoints = current;
                    break;

                case CategoryMain.Physics:
                    _categoryPhysics = current;
                    break;

                case CategoryMain.Speed:
                case CategoryMain.Handling:
                    _categorySpeedHandling = current;
                    break;
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Allows custom logic to be applied when switching between categories.
        /// </summary>
        /// <param name="categoryRows">The <see cref="CategoryRow"/> controls.</param>
        /// <param name="changedRow">The changed category row index in the array.</param>
        /// <param name="previous">The previously selected category index.</param>
        /// <param name="current">The newly selected category index.</param>
        protected override void UpdateCategories(CategoryRow[] categoryRows, int changedRow, int previous, int current)
        {
            CategoryRow crMain      = categoryRows[0];
            CategoryRow crSecondary = categoryRows[1];
            CategoryRow crTertiary  = categoryRows[2];

            if (changedRow == 0)
            {
                // Update the main categories.
                bool         fileOpen         = BinFile != null;
                CategoryMain category         = (CategoryMain)current;
                CategoryMain categoryPrevious = (CategoryMain)previous;

                crMain.ClearCategories();
                crMain.AddCategory("File");
                crMain.AddCategory("Versus Races", fileOpen);
                crMain.AddCategory("Battle Mode", fileOpen);

                // Update the secondary categories.
                crSecondary.ClearCategories();
                switch (category)
                {
                case CategoryMain.Versus:
                    crSecondary.AddCategory("All Items");
                    crSecondary.AddCategory("Mushrooms Only");
                    crSecondary.AddCategory("Shells Only");
                    crSecondary.AddCategory("Bananas Only");
                    crSecondary.AddCategory("Bob-ombs Only");
                    crSecondary.AddCategory("Frantic Mode");
                    crSecondary.AddCategory("Grand Prix");
                    crSecondary.AddCategory("Distances");
                    break;

                case CategoryMain.Battle:
                    crSecondary.AddCategory("All Items");
                    crSecondary.AddCategory("Mushrooms Only");
                    crSecondary.AddCategory("Shells Only");
                    crSecondary.AddCategory("Bananas Only");
                    crSecondary.AddCategory("Bob-ombs Only");
                    crSecondary.AddCategory("Frantic Mode");
                    break;
                }
                if ((CategoryMain)crMain.SelectedCategory == CategoryMain.Battle)
                {
                    _itemSet = Math.Min((int)CategorySecond.Frantic, _itemSet);
                }
                crSecondary.SelectedCategory = _itemSet;
            }
            else if (changedRow == 1)
            {
                // Update the tertiary categories.
                crTertiary.Visible = (CategorySecond)current != CategorySecond.Distances;
                crTertiary.ClearCategories();
                crTertiary.AddCategory("Human Player");
                crTertiary.AddCategory("Software Player");
                crTertiary.SelectedCategory = _playerType;

                // Remember the newly selected secondary category.
                _itemSet = current;
            }
            else if (changedRow == 2)
            {
                // Remember the newly selected tertiary category.
                _playerType = current;
            }

            crSecondary.Visible = (CategoryMain)crMain.SelectedCategory != CategoryMain.File;
            crTertiary.Visible  = crSecondary.Visible &&
                                  (CategorySecond)crSecondary.SelectedCategory != CategorySecond.Distances;
        }