EOS-WebAPI/Controllers/User/UserController.cs
Nidhi Bhargava d0ac8a7790 Code Commit
2025-09-04 17:30:22 +05:30

205 lines
7.1 KiB
C#

namespace VECV_WebApi.Controllers.User
{
#region Namespaces
using LoggingHelper;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using VECV_WebApi.Models.User;
#endregion
/// <summary>
/// This controller contain apis releted to user
/// </summary>
public class UserController : ApiController
{
#region Global Variable
/// <summary>
/// making object of LoggingUtility class available to this class
/// </summary>
LoggingUtility objLog = new LoggingUtility();
/// <summary>
/// making the data-log file path available to this class
/// </summary>
string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
/// <summary>
/// making data log file path available to this class
/// </summary>
string logtf = (ConfigurationManager.AppSettings["Log"]);
/// <summary>
/// making error log file path available to this class
/// </summary>
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
/// <summary>
/// making User model object available to this class
/// </summary>
UserModel objUserModel;
/// <summary>
/// making User Repository object available to this class
/// </summary>
UserRepository objUserRepository;
/// <summary>
/// making the Database connection string available to this class
/// </summary>
private string _connStr = ConfigurationManager.ConnectionStrings["Vecv_GoData"].ToString();
#endregion
#region APIs
/// <summary>
/// To get user detail, user name wise
/// </summary>
/// <param name="model">user info</param>
/// <returns>status and data</returns>
public UserModel Post([FromBody]UserModel model)
{
objUserModel = new UserModel();
try
{
objUserRepository = new UserRepository(_connStr);
objUserModel = objUserRepository.GetUserDetailUserNameWise(model);
return objUserModel;
}
catch (Exception Ex)
{
// write error log into file
objUserModel.Status = "0";
objUserModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + Ex.Message;
objLog.ErrorLogFile("GetUserDetailUserNameWise_Controller", Ex.Message, path, errorlogtf);
return objUserModel;
}
}
/// <summary>
/// To create new user
/// </summary>
/// <param name="NewUser">extra param to identify the api</param>
/// <param name="model">user details</param>
/// <returns>status 0 or 1</returns>
public UserModel Post([FromUri]string NewUser, [FromBody]UserModel model)
{
objUserModel = new UserModel();
try
{
objUserRepository = new UserRepository(_connStr);
objUserModel = objUserRepository.InsertNewUserDetail(model);
return objUserModel;
}
catch (Exception Ex)
{
// write error log into file
objLog.ErrorLogFile("InsertNewUserDetail_Controller", Ex.Message, path, errorlogtf);
objUserModel.Status = "0";
objUserModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + Ex.Message;
return objUserModel;
}
}
/// <summary>
/// To create new user
/// </summary>
/// <param name="NewUser">extra param to identify the api</param>
/// <param name="model">user details</param>
/// <returns>status 0 or 1</returns>
public UserModel Post([FromUri]string User, [FromUri]string UpdateDeleteUser, [FromBody]UserModel model)
{
objUserModel = new UserModel();
try
{
objUserRepository = new UserRepository(_connStr);
objUserModel = objUserRepository.UpdateOrDeleteUserDetail(model);
return objUserModel;
}
catch (Exception Ex)
{
// write error log into file
objLog.ErrorLogFile("UpdateOrDeleteUserDetail_Controller", Ex.Message, path, errorlogtf);
objUserModel.Status = "0";
objUserModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + Ex.Message;
return objUserModel;
}
}
/// <summary>
/// To get details of dealer, user id wise
/// </summary>
/// <param name="Dealer">extra param to identify the api</param>
/// <param name="NonUser">extra param to identify the api</param>
/// <param name="model">dealer info</param>
/// <returns>status and data</returns>
public List<DealerModel> post([FromUri]string Dealer, [FromUri]string NonUser, [FromBody]DealerModel model)
{
try
{
List<DealerModel> objList = new List<DealerModel>();
objUserRepository = new UserRepository(_connStr);
objList = objUserRepository.GetNonUserDealer(model);
return objList;
}
catch (Exception Ex)
{
// write error log into file
objLog.ErrorLogFile("GetNonUserDealer_Controller", Ex.Message, path, errorlogtf);
throw Ex;
}
}
/// <summary>
/// To get details of user/dealer, user id wise
/// </summary>
/// <param name="User">extra param to identify the api</param>
/// <param name="Dealer">extra param to identify the api</param>
/// <param name="UserType">to diffrentiate between normal user and dealer</param>
/// <param name="model">user info</param>
/// <returns>status and data</returns>
public List<UserModel> Post([FromUri]string User, [FromUri]string Dealer, [FromUri]string UserType, [FromBody]UserModel model)
{
// write data log into file
try
{
List<UserModel> objList = new List<UserModel>();
objUserRepository = new UserRepository(_connStr);
if (UserType.ToLower() == "user")
{
objList = objUserRepository.GetUserListUserIdWise(model);
}
else
{
objList = objUserRepository.GetDealerListUserIdWise(model);
}
return objList;
}
catch (Exception Ex)
{
// write error log into file
objLog.ErrorLogFile("GetUserListUserIdWise or GetDealerListUserIdWise_Controller", Ex.Message, path, errorlogtf);
throw Ex;
}
}
#endregion
}
}