using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using HRM.BO; using System.Globalization; using HRM.DA; using System.IO; using Microsoft.AspNetCore.StaticFiles; using Ease.Core.DataAccess; using static Org.BouncyCastle.Math.EC.ECCurve; using Microsoft.Extensions.Configuration; using HRM.BO.Assets; namespace HRM.UI.Controllers.Payroll { [Route("api/ExitClearance")] [ApiController] public class ExitClearanceController : ControllerBase { private readonly IAssetService _assetService; private readonly IVendorService _vendorService; private readonly IStoreService _storeService; private readonly IAssetSerialService _assetSerialService; private readonly IAssetCategoryService _assetCategoryService; private readonly IAssetSerialTranService _assetSerialTranService; private readonly IEmployeeService _employeeService; private readonly IDepartmentService _departmentService; private readonly ILocationService _locationService; private readonly IAssetItService _assetItService; private readonly IConfiguration _config; private static string _filePath = @"Documents\Asset\Asset.csv"; //policy path private static string _ePath = @"Documents\"; //private static string _filePath = @"ClientApp\Documents\Asset\Asset.csv"; //policy path //private static string _ePath = @"ClientApp\Documents\"; int startIndex = 0; public ExitClearanceController(IConfiguration config, IAssetService assetService, IVendorService vendorService, IStoreService storeService, IAssetSerialService assetSerialService, IAssetCategoryService assetCategoryService, IAssetSerialTranService assetSerialTranService, IEmployeeService employeeService, IDepartmentService departmentService, ILocationService locationService, IAssetItService assetItService) { _config = config; _assetService = assetService; _vendorService = vendorService; _storeService = storeService; _assetSerialService = assetSerialService; _assetCategoryService = assetCategoryService; _assetSerialTranService = assetSerialTranService; _employeeService = employeeService; _departmentService = departmentService; _locationService = locationService; _assetItService = assetItService; } [HttpPost] [Route("saveAsset")] public ActionResult saveAsset(Asset termParameter) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { if (termParameter.IsNew == true) { termParameter.CreatedBy = currentUser.UserID; termParameter.CreatedDate = DateTime.Today; } else { termParameter.ModifiedBy = currentUser.UserID; termParameter.ModifiedDate = DateTime.Today; } _assetService.Save(termParameter); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(termParameter); } [HttpGet("getAssets")] public ActionResult getAssets() { List assets = new List(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { assets = _assetService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(assets); } [HttpGet("getAssetsNameDescription")] public ActionResult getAssetsNameDescription() { List assets = new List(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { assets = _assetService.Get(); if (assets != null && assets.Count > 0) { foreach (var item in assets) { item.DescriptiveName = item.Name + "( " + item.Description + " )"; } } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(assets); } [HttpPost("deleteAsset")] public ActionResult DeleteAsset(Asset asset) { try { _assetService.Delete(asset.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpGet("getVendors")] public ActionResult getVendors() { List vendors = new List(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { vendors = _vendorService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(vendors); } [HttpGet("getStores")] public ActionResult getStores() { List stores = new List(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { stores = _storeService.Get(EnumStatus.Active); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(stores); } [HttpPost] [Route("saveAssetSerialList")] public ActionResult SaveAssetSerialList(List Items) { List items = new List(); List assetSerialTranList = new List(); try { CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); foreach (var oAssetSerial in Items) { oAssetSerial.CreatedBy = ouser.UserID; oAssetSerial.AssetStatus = EnumAssetStatus.Free; } items = _assetSerialService.SaveAssetSerialList(Items); if (items != null && items.Count > 0) { foreach (var oAssetSerial in Items) { if (oAssetSerial.isNewAssetTran) { var serialTran = new AssetSerialTran(); serialTran.SerialId = oAssetSerial.ID; serialTran.AssetId = oAssetSerial.AssetId; serialTran.TranType = EnumAssetTranType.Receive; serialTran.CreatedBy = ouser.UserID; serialTran.UserId = ouser.UserID; serialTran.TranDate = DateTime.Now; serialTran.CreatedDate = DateTime.Now; assetSerialTranList.Add(serialTran); } } if (assetSerialTranList != null && assetSerialTranList.Count > 0) { _assetSerialTranService.SaveAssetSerialTranList(assetSerialTranList); } } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet] [Route("GetAssetSerials/{fromDate}/{toDate}/{assetid}/{vendorid}/{storid}/{status}/{receiverType}/{receiverIds}")] public ActionResult GetAssetSerials(DateTime? fromDate, DateTime? toDate, int assetid, int vendorid, int storid, int status, int receiverType, string receiverIds) { receiverIds= receiverIds == "undefined" ? null : receiverIds; EnumAssetReceiverType? assetReceiverType = receiverType == 0 ? null : (EnumAssetReceiverType)receiverType; EnumAssetStatus? assetStatus = (EnumAssetStatus)status; List cvs = new List(); try { cvs = _assetSerialService.GetAssetSerials(fromDate, toDate, assetid, vendorid, storid, assetStatus, assetReceiverType, receiverIds); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(cvs); } [HttpGet("getAssetCatgories")] public ActionResult getAssetCatgories() { List assetCategories = new List(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = (int)ouser.PayrollTypeID; try { assetCategories = _assetCategoryService.Get(EnumStatus.Active, payrollTypeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(assetCategories); } [HttpGet("getAssetCategory/{categoryid}")] public ActionResult getAssetCategory(int categoryid) { AssetCategory assetCategories = new AssetCategory(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = (int)ouser.PayrollTypeID; try { assetCategories = _assetCategoryService.Get(categoryid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(assetCategories); } [HttpGet] [Route("GetAssetSerialPicker/{assetid}/{categoryid}/{status}")] public ActionResult GetAssetSerialPicker(int assetid, int categoryid, EnumAssetStatus? status) { List cvs = new List(); try { cvs = _assetSerialService.GetAssetSerialPicker(assetid, categoryid, status); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(cvs); } [HttpPost] [Route("saveAssetSerialTranList")] public ActionResult saveAssetSerialTranList(List Items) { string connectionString = _config.GetSection("dbSettings").GetSection("SqlCommandConnection").Value; // List allCVs = new List(); try { CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); foreach (var oAssetSerialTran in Items) { oAssetSerialTran.CreatedBy = ouser.UserID; oAssetSerialTran.UserId = ouser.UserID; if (oAssetSerialTran.AssetSerialTranAttachment != null) { if (oAssetSerialTran.AssetSerialTranAttachment.ID <= 0 && oAssetSerialTran.AssetSerialTranAttachment.PreviousFileTobase64 != null) { string[] items = oAssetSerialTran.AssetSerialTranAttachment.PreviousFileTobase64.Split(new char[] { ',', ' ' }, StringSplitOptions.None); byte[] newBytes = Convert.FromBase64String(items[1]); oAssetSerialTran.AssetSerialTranAttachment.FileAsByteArray = newBytes; oAssetSerialTran.AssetSerialTranAttachment.ConnectionString = connectionString; } } } _assetSerialTranService.SaveAssetSerialTranList(Items); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet("getLastAssetSerial/{assetId}")] public ActionResult GetLastAssetSerial(int assetId) { AssetSerial assetSerial = new AssetSerial(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { assetSerial = _assetSerialService.GetLastAssetSerial(assetId); if (assetSerial != null) { string stringCutted = assetSerial.SerialNo.Split('-').Last(); string trimSerialNo = stringCutted.TrimStart(new Char[] { '0' }); assetSerial.StartIndex = Convert.ToInt32(trimSerialNo); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(assetSerial); } [HttpGet("getAssetClearanceDamangeAmount/{empid}")] public ActionResult getAssetClearanceDamangeAmount(int empid) { double amount = 0; try { amount = this._assetSerialTranService.GetDamageAmount(empid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(amount); } [HttpGet] [Route("GetReceivedAssetSerials/{receiveDate}/{receiverType}/{receiverId}")] public ActionResult GetReceivedAssetSerials(DateTime? receiveDate, EnumAssetReceiverType? receiverType, int receiverId) { EnumAssetReceiverType? assetReceiverType = receiverType == 0 ? null : (EnumAssetReceiverType)receiverType; List cvs = new List(); try { cvs = _assetSerialService.GetReceivedAssetSerials(receiveDate, assetReceiverType, receiverId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(cvs); } [HttpGet] [Route("GetRepairedAssetSerials")] public ActionResult GetRepairedAssetSerials() { List cvs = new List(); try { cvs = _assetSerialService.GetRepairedAssetSerials(); if (cvs != null) { foreach (var item in cvs) { item.ReceivedDateString = item.RepairedDate?.ToString("dd/MM/yyyy"); } } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(cvs); } [HttpGet] [Route("GetEmployeeReceivedAssetSerial")] public ActionResult GetEmployeeReceivedAssetSerials() { List cvs = new List(); try { CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); cvs = _assetSerialService.GetReceivedAssetSerials(null, EnumAssetReceiverType.Employee, (int)ouser.EmployeeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(cvs); } [HttpPost] [Route("uploadAssetSerialList")] public ActionResult uploadAssetSerialList(List Items) { CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = (int)ouser.PayrollTypeID; int ans = 0; //List assetCategories = new List(); //assetCategories = _assetCategoryService.Get(); List assetList = new List(); assetList = _assetService.Get(); List employees = new List(); employees = _employeeService.GetAllEmps(); List deptList = new List(); deptList = _departmentService.GetAll(payrollTypeId); List locationList = new List(); locationList = _locationService.GetLocations(); List items = new List(); List itemList = new List(); List vendorList = new List(); vendorList = _vendorService.Get(); List storeList = new List(); storeList = _storeService.Get(EnumStatus.Active); //List items = new List(); List assetSerialTranList = new List(); TransactionContext tc = null; try { if (assetList == null || assetList.Count <= 0) { throw new Exception("Assets Not found"); } //if (assetCategories == null || assetCategories.Count <= 0) //{ // throw new Exception("Asset Categories Not found"); //} var count = 0; foreach (var uploadItem in Items) { count++; var oAssetSerial = new AssetSerial(); oAssetSerial.CreatedBy = ouser.UserID; oAssetSerial.AssetStatus = EnumAssetStatus.Free; oAssetSerial.Specification = uploadItem.Specification; oAssetSerial.SerialNo = uploadItem.SerialNo; //oAssetSerial.UniqueIndentifier = uploadItem.UniqueId; oAssetSerial.AssetId = uploadItem.AssetId; oAssetSerial.ReceivedDate = DateTime.Now; if (uploadItem.UniqueId != "null" && uploadItem.UniqueId != "undefined" && !String.IsNullOrEmpty(uploadItem.UniqueId)) { oAssetSerial.UniqueIndentifier = uploadItem.UniqueId; } else { oAssetSerial.UniqueIndentifier = createUniqueIdentifier(uploadItem.AssetId); startIndex++; } if (uploadItem.EmpId != "null" && uploadItem.EmpId != "undefined" && !String.IsNullOrEmpty(uploadItem.EmpId)) { var tempEmployee = employees.Find(x => x.EmployeeNo.Trim().ToLower() == uploadItem.EmpId.Trim().ToLower()); //if (tempEmployee == null) //{ // throw new Exception("Employee Not found, row no: " + count); //} //else //{ // if (!String.IsNullOrWhiteSpace(uploadItem.AssignDate)) // { // string trim = uploadItem.AssignDate.Replace("\r", ""); // trim = trim.Replace("\n", ""); // String[] strlist = trim.Split("-"); // int monthNumber = DateTime.ParseExact(strlist[1], "MMM", CultureInfo.CurrentCulture).Month; // string fullYear = "20" + strlist[2]; // // DateTime tempDate=DateTime.ParseExact(trim, "dd/MM/yyyy", null); // DateTime tempDate = new DateTime(Int32.Parse(fullYear), monthNumber, Int32.Parse(strlist[0])); // oAssetSerial.AssignDate = tempDate; // oAssetSerial.ReceivedDate = tempDate; // oAssetSerial.AssetReceiverId = tempEmployee.ID; // oAssetSerial.AssetStatus = EnumAssetStatus.Assigned; // } // else // { // throw new Exception("Date Time invalid"); // } //} if (tempEmployee != null) { if (!String.IsNullOrWhiteSpace(uploadItem.AssignDate)) { string trim = uploadItem.AssignDate.Replace("\r", ""); trim = trim.Replace("\n", ""); String[] strlist = trim.Split("-"); int monthNumber = DateTime.ParseExact(strlist[1], "MMM", CultureInfo.CurrentCulture).Month; string fullYear = "20" + strlist[2]; DateTime tempDate = new DateTime(Int32.Parse(fullYear), monthNumber, Int32.Parse(strlist[0])); oAssetSerial.AssignDate = tempDate; oAssetSerial.ReceivedDate = tempDate; oAssetSerial.AssetReceiverId = tempEmployee.ID; oAssetSerial.AssetStatus = EnumAssetStatus.Assigned; } else { throw new Exception("Date Time invalid"); } } else { throw new Exception("Please Provide Valid Employee. Employee No: " + uploadItem.EmpId); } oAssetSerial.AssetReceiverType = EnumAssetReceiverType.Employee; } if (uploadItem.DeptCode != "null" && uploadItem.DeptCode != "undefined" && !String.IsNullOrEmpty(uploadItem.DeptCode)) { // var tempDepartment = deptList.Find(x => x.Name.Trim().ToLower() == uploadItem.DeptCode.Trim().ToLower() && x.Tier == 3); //if (tempDepartment == null) //{ // throw new Exception("Department Not found,row no: " + count); //} //else //{ // oAssetSerial.AssetReceiverId = tempDepartment.ID; //} var tempDepartment = deptList.Find(x => x.Name.Trim().ToLower() == uploadItem.DeptCode.Trim().ToLower()); if (tempDepartment != null) { if (!String.IsNullOrWhiteSpace(uploadItem.AssignDate)) { string trim = uploadItem.AssignDate.Replace("\r", ""); trim = trim.Replace("\n", ""); String[] strlist = trim.Split("-"); int monthNumber = DateTime.ParseExact(strlist[1], "MMM", CultureInfo.CurrentCulture).Month; string fullYear = "20" + strlist[2]; // DateTime tempDate=DateTime.ParseExact(trim, "dd/MM/yyyy", null); DateTime tempDate = new DateTime(Int32.Parse(fullYear), monthNumber, Int32.Parse(strlist[0])); oAssetSerial.AssignDate = tempDate; oAssetSerial.ReceivedDate = tempDate; oAssetSerial.AssetReceiverId = tempDepartment.ID; oAssetSerial.AssetStatus = EnumAssetStatus.Assigned; } else { throw new Exception("Date Time invalid"); } } else { throw new Exception("Please Provide Valid Department.Department No: " + uploadItem.DeptCode); } oAssetSerial.AssetReceiverType = EnumAssetReceiverType.Department; } else if (uploadItem.LocationCode != "null" && uploadItem.LocationCode != "undefined" && !String.IsNullOrEmpty(uploadItem.LocationCode)) { //var tempLocation = locationList.Find(x => x.Name.Trim().ToLower() == uploadItem.LocationCode.Trim().ToLower() && x.Tier == 2); //if (tempLocation == null) //{ // throw new Exception("Location Not found, row no: " + count); //} //else //{ // oAssetSerial.AssetReceiverId = tempLocation.ID; //} var tempLocation = locationList.Find(x => x.Name.Trim().ToLower() == uploadItem.LocationCode.Trim().ToLower()); if (tempLocation != null) { if (!String.IsNullOrWhiteSpace(uploadItem.AssignDate)) { string trim = uploadItem.AssignDate.Replace("\r", ""); trim = trim.Replace("\n", ""); String[] strlist = trim.Split("-"); int monthNumber = DateTime.ParseExact(strlist[1], "MMM", CultureInfo.CurrentCulture).Month; string fullYear = "20" + strlist[2]; // DateTime tempDate=DateTime.ParseExact(trim, "dd/MM/yyyy", null); DateTime tempDate = new DateTime(Int32.Parse(fullYear), monthNumber, Int32.Parse(strlist[0])); oAssetSerial.AssignDate = tempDate; oAssetSerial.ReceivedDate = tempDate; oAssetSerial.AssetReceiverId = tempLocation.ID; oAssetSerial.AssetStatus = EnumAssetStatus.Assigned; } else { throw new Exception("Date Time invalid"); } } else { throw new Exception("Please Provide Valid Location.Location No:" + uploadItem.LocationCode); } oAssetSerial.AssetReceiverType = EnumAssetReceiverType.Location; } if ((uploadItem.EmpId == "null" || uploadItem.EmpId == "undefined" || String.IsNullOrEmpty(uploadItem.EmpId)) && (uploadItem.DeptCode == "null" || uploadItem.DeptCode == "undefined" || String.IsNullOrEmpty(uploadItem.DeptCode)) && (uploadItem.LocationCode == "null" || uploadItem.LocationCode == "undefined" || String.IsNullOrEmpty(uploadItem.LocationCode))) { oAssetSerial.AssetStatus = EnumAssetStatus.Free; oAssetSerial.AssetReceiverType = EnumAssetReceiverType.None; } if (uploadItem.Store != "null" && uploadItem.Store != "undefined" && !String.IsNullOrEmpty(uploadItem.Store)) { var tempStore = storeList.Find(x => x.Name.Trim().ToLower() == uploadItem.Store.Trim().ToLower()); if (tempStore == null) { throw new Exception("Store Not found, row no: " + count); } else { oAssetSerial.StoreId = tempStore.ID; } } else { throw new Exception("Store Not found, row no: " + count); } if (uploadItem.Vendor != "null" && uploadItem.Vendor != "undefined" && !String.IsNullOrEmpty(uploadItem.Vendor)) { var tempVendor = vendorList.Find(x => x.Name.Trim().ToLower() == uploadItem.Vendor.Trim().ToLower()); if (tempVendor == null) { throw new Exception("Vendor Not found, row no: " + count); } else { oAssetSerial.VendorId = tempVendor.ID; } } if (uploadItem.Price != null) { oAssetSerial.Price = uploadItem.Price; } oAssetSerial.CreatedBy = ouser.UserID; oAssetSerial.CreatedDate = DateTime.Today; oAssetSerial.StoreId = oAssetSerial.StoreId == 0 ? null : oAssetSerial.StoreId; oAssetSerial.VendorId = oAssetSerial.VendorId == 0 ? null : oAssetSerial.VendorId; itemList.Add(oAssetSerial); } tc = TransactionContext.Begin(true); items = _assetSerialService.SaveAssetSerialList(tc,itemList); if (items != null && items.Count > 0) { foreach (var oAssetSerial in items) { if (oAssetSerial.isNewAssetTran) { var serialTran = new AssetSerialTran(); serialTran.SerialId = oAssetSerial.ID; serialTran.AssetId = oAssetSerial.AssetId; if (oAssetSerial.AssetStatus == EnumAssetStatus.Free) serialTran.TranType = EnumAssetTranType.Receive; else serialTran.TranType = EnumAssetTranType.Assign; serialTran.CreatedBy = ouser.UserID; serialTran.UserId = ouser.UserID; serialTran.TranDate = DateTime.Now; serialTran.CreatedDate = DateTime.Now; serialTran.AssetReceiverId = oAssetSerial.AssetReceiverId; serialTran.AssetReceiverType = oAssetSerial.AssetReceiverType; serialTran.AssignDate = oAssetSerial.AssignDate; serialTran.UploadReceiveDate = oAssetSerial.ReceivedDate; serialTran.StoreId = (int)oAssetSerial.StoreId; serialTran.VendorId = (int)oAssetSerial.VendorId; assetSerialTranList.Add(serialTran); } } if (assetSerialTranList != null && assetSerialTranList.Count > 0) { _assetSerialTranService.SaveAssetSerialTranList(tc,assetSerialTranList); } if(items != null && items.Count > 0) { var item = items.Where(y => !String.IsNullOrEmpty(y.Specification)).FirstOrDefault(); _assetService.UpdateAssetSpecification(tc,item); } } tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("deleteAssetSerial")] public ActionResult DeleteAssetSerial(AssetSerial item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { _assetSerialService.Delete(item.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpGet] [Route("generateSerial/{assetid}/{qty}")] public ActionResult GetGenerateSerial(int assetid, int qty) { List assetSerials = new List(); AssetSerial lastAssetSerial = new AssetSerial(); Asset asset = new Asset(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { int startIndex = 0; lastAssetSerial = _assetSerialService.GetLastAssetSerial(assetid); asset = _assetService.Get(assetid); if (lastAssetSerial != null) { string stringCutted = lastAssetSerial.UniqueIndentifier.Split('-').Last(); string trimSerialNo = stringCutted.TrimStart(new Char[] { '0' }); startIndex = lastAssetSerial.StartIndex = Convert.ToInt32(trimSerialNo); } //var dd = string(today.getdate()).padstart(2, '0'); //var mm = string(today.getmonth() + 1).padstart(2, '0'); //january is 0! //var yyyy = today.getfullyear(); string dd = DateTime.Now.ToString("dd").PadLeft(2, '0'); string mm = DateTime.Now.ToString("mm").PadLeft(2, '0'); var yyyy = DateTime.Now.ToString("yyyy"); string date = dd + '/' + mm + '/' + yyyy; for (int i = 0; i < qty; i++) { startIndex++; var temp = new AssetSerial(); temp.AssetId = assetid; temp.CreatedDate = DateTime.Now; temp.UniqueIndentifier = asset.Code + "-" + date + "-" + startIndex.ToString().PadLeft(4, '0'); assetSerials.Add(temp); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(assetSerials); } public string createUniqueIdentifier(int assetid) { AssetSerial lastAssetSerial = new AssetSerial(); Asset asset = new Asset(); lastAssetSerial = _assetSerialService.GetLastAssetSerial(assetid); asset = _assetService.Get(assetid); if (lastAssetSerial != null) { string stringCutted = lastAssetSerial.UniqueIndentifier.Split('-').Last(); string trimSerialNo = stringCutted.TrimStart(new Char[] { '0' }); lastAssetSerial.StartIndex = Convert.ToInt32(trimSerialNo); if (lastAssetSerial.StartIndex > startIndex) startIndex = lastAssetSerial.StartIndex; if (lastAssetSerial.StartIndex == 0 && startIndex == 0) { startIndex++; } } if (startIndex == 0) { startIndex++; } string dd = DateTime.Now.ToString("dd").PadLeft(2, '0'); string mm = DateTime.Now.ToString("mm").PadLeft(2, '0'); var yyyy = DateTime.Now.ToString("yyyy"); string date = dd + '/' + mm + '/' + yyyy; var uniqueIndentifier = asset.Code + "-" + date + "-" + startIndex.ToString().PadLeft(4, '0'); return uniqueIndentifier; } [HttpGet("getAssetNextCode")] public ActionResult GetAssetNextCode() { string code = ""; try { code = _assetService.GetNextCode(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(code); } //getAssetIT [HttpGet("getAssetIt/{assetItId}")] public ActionResult getAssetIt(int assetItId) { AssetIt assetIt = new AssetIt(); CurrentUser ouser = CurrentUser.GetCurrentUser(HttpContext.User); try { assetIt = _assetItService.Get(assetItId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(assetIt); } //AssetIt Serial Picker [HttpGet] [Route("GetAssetItSerialPicker/{assetid}/{categoryid}/{assetitid}/{assetserialid}")] public ActionResult GetAssetItSerialPicker(int assetid, int categoryid, int assetitid, int assetserialid) { List cvs = new List(); try { cvs = _assetItService.GetAssetItSerialPicker(assetid, categoryid, assetitid, assetserialid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(cvs); } //Get All Asset It [HttpGet("getAllAssetIt")] public ActionResult GetAllAssetIt() { List assets = new List(); try { assets = _assetItService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(assets); } //Save Asset It [HttpPost] [Route("saveAssetIt")] public ActionResult SaveAssetIt(AssetIt item) { try { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (item.IsNew) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } _assetItService.Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } //Delete It [HttpPost("deleteAssetIt")] public ActionResult DeleteAssetIt(AssetIt assetIt) { try { _assetItService.Delete(assetIt.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpGet] [Route("get-asset-file")] public async Task GetAssetFile() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); string contentType = ""; try { var filePath = System.IO.Path.Combine(System.Environment.CurrentDirectory, _filePath); Stream memory = new MemoryStream(); byte[] buffer = new byte[16 * 1024]; contentType = GetFileType("Asset.csv"); buffer = System.IO.File.ReadAllBytes(filePath); string file = Convert.ToBase64String(buffer); return Ok(file); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } public string GetFileType(string originalFileName) { string fileName = originalFileName; string contentType; new FileExtensionContentTypeProvider().TryGetContentType(fileName, out contentType); return contentType ?? "application/vnd.ms-excel"; } } }