public BaseResponse <Response> SaveOrUpdate(CustomerDto customer)
        {
            Response response = null;

            try
            {
                using (SqlConnection con = new SqlConnection(constring))
                {
                    using (SqlCommand cmd = new SqlCommand("Usp_SaveOrUpdateCustomer", con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@Id", customer.Id);
                        cmd.Parameters.AddWithValue("@CustomerName", customer.CustomerName);
                        cmd.Parameters.AddWithValue("@ContributionNumber", customer.ContributionNumber);
                        cmd.Parameters.AddWithValue("@Address", customer.Address);
                        cmd.Parameters.AddWithValue("@City", customer.City);
                        cmd.Parameters.AddWithValue("@PhoneNumber", customer.PhoneNumber);
                        cmd.Parameters.AddWithValue("@MobileNumber", customer.MobileNumber);
                        cmd.Parameters.AddWithValue("@OpeningBalance", customer.OpeningBalance);
                        cmd.Parameters.AddWithValue("@CreditLimit", customer.CreditLimit);
                        cmd.Parameters.AddWithValue("@StartCreditPeriod", customer.StartCreditPeriod);
                        cmd.Parameters.AddWithValue("@EndCreditPeriod", customer.EndCreditPeriod);
                        cmd.Parameters.AddWithValue("@DGEApproved", customer.DGEApproved);
                        cmd.Parameters.AddWithValue("@FaxNumber", customer.FaxNumber);
                        cmd.Parameters.AddWithValue("@Attendent", customer.Attendent);
                        cmd.Parameters.AddWithValue("@CompanyId", customer.CompanyId);
                        cmd.Parameters.AddWithValue("@IsActive", customer.IsActive);

                        SqlParameter parameter = new SqlParameter();
                        parameter           = new SqlParameter("@message", SqlDbType.VarChar, 255);
                        parameter.Direction = ParameterDirection.Output;
                        cmd.Parameters.Add(parameter);
                        parameter           = new SqlParameter("@customerId", DbType.Int64);
                        parameter.Direction = ParameterDirection.Output;
                        cmd.Parameters.Add(parameter);
                        parameter           = new SqlParameter("@statusCode", DbType.Int64);
                        parameter.Direction = ParameterDirection.Output;
                        cmd.Parameters.Add(parameter);

                        con.Open();
                        cmd.ExecuteNonQuery();
                        response            = new Response();
                        response.Message    = cmd.Parameters["@message"].Value.ToString();
                        response.Id         = Int32.Parse(cmd.Parameters["@customerId"].Value.ToString());
                        response.StatusCode = Int32.Parse(cmd.Parameters["@statusCode"].Value.ToString());
                        con.Close();

                        if (response != null)
                        {
                            return(ResponseFactory.SuccessForType <Response>(response, "Success."));
                        }
                    }
                }
                return(ResponseFactory.ErrorForType <Response>("Something went wrong."));
            }
            catch (Exception ex)
            {
                return(ResponseFactory.ErrorForType <Response>(ex.Message));
            }
        }
Beispiel #2
0
        public BaseResponse <LoginViewModel> GetCompany(int userId, int companyId)
        {
            LoginViewModel viewModel = null;

            if (userId > 0 && companyId > 0)
            {
                var getUser = TCSOfficeDbContext.Logins.FirstOrDefault(z => z.Id == userId);
                if (getUser != null)
                {
                    var getCompany = TCSOfficeDbContext.Companies.FirstOrDefault(z => z.Id == companyId);
                    if (getCompany != null)
                    {
                        viewModel             = new LoginViewModel();
                        viewModel.CompanyName = getCompany.CompanyName;
                        viewModel.Address     = getCompany.Address;
                        viewModel.Phone       = getCompany.Phone;
                        viewModel.Email       = getUser.Email;
                        viewModel.UserName    = getUser.UserName;
                        return(ResponseFactory.SuccessForType <LoginViewModel>(viewModel, "Successfully fetched details."));
                    }
                }
                return(ResponseFactory.ErrorForType <LoginViewModel>("Something went wrong."));
            }
            return(ResponseFactory.ErrorForType <LoginViewModel>("Company is invalid."));
        }