public async Task <HttpResponseMessage> Post([FromBody] InvStockProductRegistrationModel mInvStockProductRegistrationModel)
        {
            var    formatter = RequestFormat.JsonFormaterString();
            string msg       = "";

            try
            {
                if (mInvStockProductRegistrationModel.Id == 0)
                {
                    if (mInvStockProductRegistrationModel.ProductName == "")
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK,
                                                      new Confirmation {
                            Output = "error", Msg = "Product Name  is Empty"
                        }, formatter));
                    }
                    else if (mInvStockProductRegistrationModel.ProductCategory == 0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK,
                                                      new Confirmation {
                            Output = "error", Msg = "Please Select Product Category"
                        }, formatter));
                    }
                    else if (mInvStockProductRegistrationModel.Unit == "")
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK,
                                                      new Confirmation {
                            Output = "error", Msg = " Unit is Empty"
                        }, formatter));
                    }
                    else
                    {
                        msg = await _gtInvStokeProductRegistrationGatway.Save(mInvStockProductRegistrationModel);

                        return(Request.CreateResponse(HttpStatusCode.OK,
                                                      new Confirmation {
                            Output = "success", Msg = msg
                        }, formatter));
                    }
                }
                else
                {
                    msg = await _gtInvStokeProductRegistrationGatway.Update(mInvStockProductRegistrationModel);

                    return(Request.CreateResponse(HttpStatusCode.OK,
                                                  new Confirmation {
                        Output = "Update success", Msg = msg
                    }, formatter));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, new Confirmation {
                    Output = "error", Msg = ex.ToString()
                }, formatter));
            }
        }
Example #2
0
        public Task <string> Update(InvStockProductRegistrationModel aModel)
        {
            try
            {
                string       msg   = "";
                const string query = @"Update tbl_INVSTOCK_SalesProductList SET ProductName=@ProductName,ProductCategoryId=@ProductCategoryId,Unit=@Unit,Valid=@Valid,UserName=@UserName ,
                                       RackNumber=@RackNumber, cellNumber=@cellNumber, DepreciationMethodId=@DepreciationMethodId, DepreciationAmount=@DepreciationAmount, DepreciationAmountType=@DepreciationAmountType, AssetType=@AssetType, MinimumQuantity=@MinimumQuantity, EconomicQuantity=@EconomicQuantity Where Id=@Id";
                Con.Open();
                var cmd = new SqlCommand(query, Con);
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@Id", aModel.Id);
                cmd.Parameters.AddWithValue("@ProductName", aModel.ProductName);
                cmd.Parameters.AddWithValue("@ProductCategoryId", aModel.ProductCategory);
                cmd.Parameters.AddWithValue("@Unit", aModel.Unit);
                cmd.Parameters.AddWithValue("@Valid", 1);
                cmd.Parameters.AddWithValue("@UserName", aModel.UserName);
                cmd.Parameters.AddWithValue("@RackNumber", aModel.rackNumber);
                cmd.Parameters.AddWithValue("@cellNumber", aModel.cellNumber);
                cmd.Parameters.AddWithValue("@DepreciationMethodId", aModel.DepreciationMethodId);
                cmd.Parameters.AddWithValue("@DepreciationAmount", aModel.DepreciationAmount);
                cmd.Parameters.AddWithValue("@DepreciationAmountType", aModel.DepreciationAmountType);
                cmd.Parameters.AddWithValue("@AssetType", aModel.AssetType);
                cmd.Parameters.AddWithValue("@MinimumQuantity", aModel.MinimumQuantity);
                cmd.Parameters.AddWithValue("@EconomicQuantity", aModel.EconomicQuantity);

                int rtn = cmd.ExecuteNonQuery();
                msg = rtn == 1 ? "Saved Success" : "Saved Failed";
                Con.Close();
                // return msg;
                return(Task.FromResult(msg));
            }
            catch (Exception exception)
            {
                if (Con.State == ConnectionState.Open)
                {
                    Con.Close();
                }
                return(Task.FromResult(exception.Message));
            }
        }