Esempio n. 1
0
        public async Task <ActionResult> Put(string id, [FromBody] MenuTest value)
        {
            try
            {
                //kiểm tra giống ID hay không
                if (id.Equals(value.Id, StringComparison.OrdinalIgnoreCase))
                {
                    value.Code = value.Code.ToLower().Trim();
                    //cập nhật UpdatedOn
                    value.UpdatedOn = DateTime.Now;
                    //không cho chỉnh người tạo và IsActive- đề phòng hack

                    /*value.CreatedBy = null;
                     * value.IsActive = true;*/
                    //cập nhật UpdatedOn
                    value.UpdatedOn = DateTime.Now;
                    value.UpdatedBy = UserClaim.UserId;
                    //gọi hàm update
                    var result = await _serviceMenuTest.UpdateAsync(id, value);

                    return(Ok(result));
                }
                return(BadRequest(StaticVar.MessageNotFound));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Esempio n. 2
0
 public async Task <ActionResult <MenuTest> > Post([FromBody] MenuTest data)
 {
     try
     {
         data.Code      = data.Code.ToLower().Trim();
         data.CreatedOn = DateTime.Now;
         data.CreatedBy = UserClaim.UserId;
         return(await _serviceMenuTest.InsertAsync(data));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
Esempio n. 3
0
        static void programLoader(int programToLoad)
        {
            switch (programToLoad)
            {
            case (0):
                MenuTest menuTest = new MenuTest();
                menuTest.LoadMenu();
                break;

            case (1):
                FormatChecker formatChecker = new FormatChecker();
                formatChecker.FormatCheck();
                break;

            case (2):
                PrimeToHundred primeToHundred = new PrimeToHundred();
                primeToHundred.PrimToHundred();
                break;

            case (3):
                EliteNumCheck eliteNumCheck = new EliteNumCheck();
                eliteNumCheck.ElitePrime();
                break;

            case (4):
                AnimalEngine animalEngine = new AnimalEngine();
                animalEngine.EngineStart();
                break;

            case (5):
                CarHandler carHandler = new CarHandler();
                carHandler.HandleCars();
                break;

            case (6):
                CombatSystem combatSystem = new CombatSystem(new Katana());
                combatSystem.CombatEngine();
                break;

            default:
                break;
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> AddOrEdit(string id, MenuTest data)
        {
            if (ModelState.IsValid)
            {
                //Insert
                if (String.IsNullOrEmpty(id))
                {
                    try
                    {
                        // check isset code ?
                        if (await ApiHelper <bool> .CheckIssetCode($"{StaticVar.ApiUrlMenus}/ExistsCode/{data.Code}"))
                        {
                            ModelState.AddModelError("", StaticVar.MessageCodeDuplicated);
                            await SetViewData(data.Parent);

                            return(Json(new
                            {
                                isValid = false,
                                html = MyViewHelper.RenderRazorViewToString(this, "AddOrEdit", data)
                            }));
                        }
                        else
                        {
                            try
                            {
                                MenuTest result = await ApiHelper <MenuTest> .RunPostAsync(StaticVar.ApiUrlMenus, data);
                            }
                            catch (Exception ex)
                            {
                                await SetViewData();

                                return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "Error", new ErrorViewModel {
                                        RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, Message = ex.Message
                                    }) }));
                            }
                        }
                    }
                    catch (Exception ex) { return(Json(new { isValid = false, mes = ex.Message })); }
                }
                //Update
                else
                {
                    try
                    {
                        await ApiHelper <MenuTest> .RunPutAsync($"{StaticVar.ApiUrlMenus}/{id}", data);
                    }
                    catch (Exception ex)
                    {
                        return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "Error", new ErrorViewModel {
                                RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, Message = ex.Message
                            }) }));
                    }
                }
                return(Json(new
                {
                    isValid = true,
                    html = MyViewHelper.RenderRazorViewToString(this, "_ViewAll", await GetListMenu())
                }));
            }
            else
            {
                await SetViewData(data.Parent);
            }
            return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "AddOrEdit", data) }));
        }
Esempio n. 5
0
        public async Task <MenuTest> GetDetails(string id)
        {
            MenuTest data = await _serviceMenuTest.GetByIDAsync(id);

            return(data);
        }