Exemplo n.º 1
0
        public async Task <ActionResult> Put(string id, [FromBody] SystemFunctionTest 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 _serviceSysFuctionTest.UpdateAsync(id, value);

                    return(Ok(result));
                }
                return(BadRequest(StaticVar.MessageNotFound));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Exemplo n.º 2
0
 public async Task <ActionResult <SystemFunctionTest> > Post([FromBody] SystemFunctionTest data)
 {
     try
     {
         data.Code      = data.Code.ToLower().Trim();
         data.CreatedOn = DateTime.Now;
         data.CreatedBy = UserClaim.UserId;
         return(await _serviceSysFuctionTest.InsertAsync(data));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        public async Task <IActionResult> AddOrEdit(string id, SystemFunctionTest data)
        {
            if (ModelState.IsValid)
            {
                //Insert
                if (String.IsNullOrEmpty(id))
                {
                    try
                    {
                        // Check isset code ?
                        if (await ApiHelper <bool> .CheckIssetCode($"{StaticVar.ApiUrlSystemFunctions}/ExistsCode/{data.Code}"))
                        {
                            ModelState.AddModelError("", StaticVar.MessageCodeDuplicated);
                            return(Json(new
                            {
                                isValid = false,
                                html = MyViewHelper.RenderRazorViewToString(this, "AddOrEdit", data)
                            }));
                        }
                        else
                        {
                            try
                            {
                                SystemFunctionTest result = await ApiHelper <SystemFunctionTest> .RunPostAsync(StaticVar.ApiUrlSystemFunctions, 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
                                    }) }));
                            }
                        }
                    }
                    catch (Exception ex) { return(Json(new { isValid = false, mes = ex.Message })); }
                }
                //Update
                else
                {
                    // Check isset code , but allow itself !!
                    SystemFunctionTest _object = await ApiHelper <SystemFunctionTest> .RunGetAsync($"{StaticVar.ApiUrlSystemFunctions}/GetDetails/{data.Code}");

                    if (_object == null || _object.Id.Equals(data.Id))
                    {
                        try
                        {
                            await ApiHelper <SystemFunctionTest> .RunPutAsync($"{StaticVar.ApiUrlSystemFunctions}/{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
                                }) }));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", StaticVar.MessageCodeDuplicated);
                        return(Json(new
                        {
                            isValid = false,
                            html = MyViewHelper.RenderRazorViewToString(this, "AddOrEdit", data)
                        }));
                    }
                }
                return(Json(new
                {
                    isValid = true,
                    html = MyViewHelper.RenderRazorViewToString(this, "_ViewAll")
                }));
            }

            return(Json(new { isValid = false, html = MyViewHelper.RenderRazorViewToString(this, "AddOrEdit", data) }));
        }
Exemplo n.º 4
0
        public async Task <SystemFunctionTest> GetDetails(string id)
        {
            SystemFunctionTest _data = await _serviceSysFuctionTest.GetByIDAsync(id);

            return(_data);
        }