public async Task <HttpResponseMessage> Save_tbl_PHAR_PRODUCT([FromBody] PharProductInfoModel aModel)
        {
            var formate = RequestFormat.JsonFormaterString();

            try{
                if (string.IsNullOrEmpty(aModel.Name))
                {
                    return(Request.CreateResponse(HttpStatusCode.OK,
                                                  new Confirmation {
                        Output = "error", Msg = "Name is Empty"
                    }, formate));
                }

                if (aModel.GroupId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK,
                                                  new Confirmation {
                        Output = "error", Msg = "PdGroupe Id Cannot be Zero"
                    }, formate));
                }

                else
                {
                    if (_gt.FncSeekRecordNew("tbl_PHAR_PRODUCT", "Id=" + aModel.Id + "") == false)
                    {
                        string msg = await _gt.Save(aModel);

                        return(Request.CreateResponse(HttpStatusCode.OK,
                                                      new Confirmation {
                            Output = "success", Msg = msg
                        }, formate));
                    }
                    else
                    {
                        string msg = await _gt.Update(aModel);

                        return(Request.CreateResponse(HttpStatusCode.OK,
                                                      new Confirmation {
                            Output = "success", Msg = msg
                        }, formate));
                    }
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.OK
                                              , new Confirmation {
                    Output = "error", Msg = ex.ToString()
                }, formate));
            }
        }
        public Task <string> Update(PharProductInfoModel aModel)
        {
            try
            {
                const string query = @"UPDATE tbl_PHAR_PRODUCT SET CompanyId=@CompanyId,Name=@Name,GenericId=@GenericId,ProductUnit=@ProductUnit,Tp=@Tp,SalesPrice=@SalesPrice,ReminderStock=@ReminderStock,GroupId=@GroupId,RackNo=@RackNo,RowNo=@RowNo,UserName=@UserName,BranchId=@BranchId
                                        WHERE Id=@Id";
                Con.Open();
                var cmd = new SqlCommand(query, Con);
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@Id", aModel.Id);
                cmd.Parameters.AddWithValue("@CompanyId", aModel.CompanyId);
                cmd.Parameters.AddWithValue("@Name", aModel.Name);
                cmd.Parameters.AddWithValue("@GenericId", aModel.GenericId);
                cmd.Parameters.AddWithValue("@ProductUnit", aModel.ProductUnit);
                cmd.Parameters.AddWithValue("@Tp", aModel.Tp);
                cmd.Parameters.AddWithValue("@SalesPrice", aModel.SalesPrice);
                cmd.Parameters.AddWithValue("@ReminderStock", aModel.ReminderStock);
                cmd.Parameters.AddWithValue("@GroupId", aModel.GroupId);
                cmd.Parameters.AddWithValue("@RackNo", aModel.RackNo);
                cmd.Parameters.AddWithValue("@RowNo", aModel.RowNo);
                cmd.Parameters.AddWithValue("@UserName", aModel.UserName);
                cmd.Parameters.AddWithValue("@BranchId", GetBranchIdByuserNameOpenCon(aModel.UserName));


                cmd.ExecuteNonQuery();
                Con.Close();
                return(Task.FromResult <string>("Update Successful"));
            }
            catch (Exception exception)
            {
                if (Con.State == ConnectionState.Open)
                {
                    Con.Close();
                }
                return(Task.FromResult(exception.Message));
            }
        }
        public Task <string> Save(PharProductInfoModel aModel)
        {
            try
            {
                string code = GetMaxId("tbl_PHAR_PRODUCT", "Code");
                Con.Open();
                const string query = @"INSERT INTO tbl_PHAR_PRODUCT (CompanyId,Name,Code,GenericId,ProductUnit,Tp,SalesPrice,ReminderStock,GroupId,RackNo,RowNo,UserName,BranchId) 
										VALUES (@CompanyId,@Name,@Code,@GenericId,@ProductUnit,@Tp,@SalesPrice,@ReminderStock,@GroupId,@RackNo,@RowNo,@UserName,@BranchId)"                                        ;

                var cmd = new SqlCommand(query, Con);
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@CompanyId", aModel.CompanyId);
                cmd.Parameters.AddWithValue("@Name", aModel.Name);
                cmd.Parameters.AddWithValue("@Code", code);
                cmd.Parameters.AddWithValue("@GenericId", aModel.GenericId);
                cmd.Parameters.AddWithValue("@ProductUnit", aModel.ProductUnit);
                cmd.Parameters.AddWithValue("@Tp", aModel.Tp);
                cmd.Parameters.AddWithValue("@SalesPrice", aModel.SalesPrice);
                cmd.Parameters.AddWithValue("@ReminderStock", aModel.ReminderStock);
                cmd.Parameters.AddWithValue("@GroupId", aModel.GroupId);
                cmd.Parameters.AddWithValue("@RackNo", aModel.RackNo);
                cmd.Parameters.AddWithValue("@RowNo", aModel.RowNo);
                cmd.Parameters.AddWithValue("@UserName", aModel.UserName);
                cmd.Parameters.AddWithValue("@BranchId", GetBranchIdByuserNameOpenCon(aModel.UserName));
                cmd.ExecuteNonQuery();
                Con.Close();
                return(Task.FromResult("Save successful"));
            }
            catch (Exception exception)
            {
                if (Con.State == ConnectionState.Open)
                {
                    Con.Close();
                }
                return(Task.FromResult(exception.Message));
            }
        }