Ejemplo n.º 1
0
        public async Task <IActionResult> RegisterUnit([FromBody] TblUnit unit)
        {
            var result = await Task.Run(() =>
            {
                APIResponse apiResponse = null;
                if (unit == null)
                {
                    return(Ok(new APIResponse()
                    {
                        status = APIStatus.PASS.ToString(), response = "object can not be null"
                    }));
                }

                try
                {
                    var unitlist = new UnitHelpers().GetList(unit.UnitName);
                    if (unitlist.Count() > 0)
                    {
                        return(Ok(new APIResponse()
                        {
                            status = APIStatus.PASS.ToString(), response = $"unit Code {nameof(unitlist)} is already exists ,Please Use Different Code "
                        }));
                    }

                    var result = new UnitHelpers().Register(unit);
                    if (result != null)
                    {
                        apiResponse = new APIResponse()
                        {
                            status = APIStatus.PASS.ToString(), response = result
                        };
                    }
                    else
                    {
                        apiResponse = new APIResponse()
                        {
                            status = APIStatus.FAIL.ToString(), response = "Registration Failed."
                        };
                    }

                    return(Ok(apiResponse));
                }
                catch (Exception ex)
                {
                    return(Ok(new APIResponse()
                    {
                        status = APIStatus.FAIL.ToString(), response = ex.Message
                    }));
                }
            });

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetUnitList()
        {
            var result = await Task.Run(() =>
            {
                try
                {
                    var unitList = new UnitHelpers().GetList();
                    if (unitList.Count() > 0)
                    {
                        dynamic expdoObj  = new ExpandoObject();
                        expdoObj.unitList = unitList;
                        return(Ok(new APIResponse {
                            status = APIStatus.PASS.ToString(), response = expdoObj
                        }));
                    }
                    else
                    {
                        return(Ok(new APIResponse {
                            status = APIStatus.FAIL.ToString(), response = "No Data Found."
                        }));
                    }
                }
                catch (Exception ex)
                {
                    return(Ok(new APIResponse()
                    {
                        status = APIStatus.FAIL.ToString(), response = ex.Message
                    }));
                }
                //try
                //{
                //    dynamic expando = new ExpandoObject();
                //    var unitList = new UnitHelpers().GetList();
                //    return Ok(new APIResponse() { status = APIStatus.PASS.ToString(), response = expando });
                //}
                //catch (Exception ex)
                //{
                //    return Ok(new APIResponse() { status = APIStatus.FAIL.ToString(), response = ex.Message });
                //}
            });

            return(result);
        }