Commit 73cf0682 authored by Sandeep Sagar Panjala's avatar Sandeep Sagar Panjala

initial commit

parent e1c9a299
namespace Hims.Api.Controllers
{
using System.Net;
using Domain.Configurations;
using Microsoft.AspNetCore.Mvc;
/// <summary>
/// The home controller.
/// </summary>
public class HomeController : Controller
{
/// <summary>
/// The API docs url.
/// </summary>
private readonly string apiDocsUrl;
/// <summary>
/// The identity server url.
/// </summary>
private readonly string identityServerUrl;
/// <summary>
/// The swagger url.
/// </summary>
private readonly string swaggerUrl;
/// <summary>
/// Initializes a new instance of the <see cref="HomeController"/> class.
/// </summary>
/// <param name="applicationConfiguration">
/// The application configuration.
/// </param>
public HomeController(IApplicationConfiguration applicationConfiguration)
{
this.apiDocsUrl = applicationConfiguration.APILink + "api-docs";
this.identityServerUrl = applicationConfiguration.APILink + ".well-known/openid-configuration";
this.swaggerUrl = applicationConfiguration.APILink + "swagger/v" + applicationConfiguration.Version + "/swagger.json";
}
/// <summary>
/// The index.
/// </summary>
/// <returns>
/// The <see cref="IActionResult"/>.
/// </returns>
public IActionResult Index()
{
this.ViewBag.ApiDocsUrl = this.apiDocsUrl;
this.ViewBag.IdentityServerUrl = this.identityServerUrl;
this.ViewBag.SwaggerUrl = this.swaggerUrl;
return this.View();
}
/// <summary>
/// The index.
/// </summary>
/// <returns>
/// The <see cref="IActionResult"/>.
/// </returns>
public IActionResult IdentityServer()
{
var client = new WebClient();
this.ViewBag.Result = client.DownloadString(this.identityServerUrl);
this.ViewBag.ApiDocsUrl = this.apiDocsUrl;
return this.View();
}
/// <summary>
/// The index.
/// </summary>
/// <returns>
/// The <see cref="IActionResult"/>.
/// </returns>
public IActionResult Swagger()
{
var client = new WebClient();
this.ViewBag.Result = client.DownloadString(this.swaggerUrl);
this.ViewBag.ApiDocsUrl = this.apiDocsUrl;
return this.View();
}
/// <summary>
/// The Not Found.
/// </summary>
/// <returns>
/// The <see cref="IActionResult"/>.
/// </returns>
public new IActionResult NotFound() => this.View("_NotFound");
/// <summary>
/// The error.
/// </summary>
/// <returns>
/// The <see cref="IActionResult"/>.
/// </returns>
public IActionResult Error() => this.View("_Error");
}
}
\ No newline at end of file
namespace Hims.Api.Controllers
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Domain.Services;
using Hims.Api.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.CSharp;
using Npgsql;
using Shared.DataFilters;
using Shared.EntityModels;
using Shared.Library.Enums;
using Shared.UserModels;
using Utilities;
/// <inheritdoc />
[Authorize]
[Route("api/hwc-patient")]
[Consumes("application/json")]
[Produces("application/json")]
public class HwcPatientController : BaseController
{
/// <summary>
/// The coupon services.
/// </summary>
private readonly IHwcPatientService hocPatientService;
/// <summary>
/// The audit log services.
/// </summary>
private readonly IAuditLogService auditLogServices;
/// <inheritdoc />
public HwcPatientController(IHwcPatientService hocPatientService, IAuditLogService auditLogServices)
{
this.hocPatientService = hocPatientService;
this.auditLogServices = auditLogServices;
}
/// <summary>
/// Inserts the hoc asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="location">The location.</param>
/// <returns></returns>
[HttpPost]
[Route("insert")]
public async Task<ActionResult> InsertHocAsync([FromBody] HwcPatientModel model, [FromHeader] LocationHeader location)
{
model = (HwcPatientModel)EmptyFilter.Handler(model);
model.LocationId = !string.IsNullOrEmpty(location.LocationId) ? int.Parse(location.LocationId) : (int?)null;
var response = await this.hocPatientService.InsertAsync(model);
try
{
if (response > 0)
{
var auditLogModel = new AuditLogModel
{
AccountId = model.CreatedBy,
LogTypeId = (int)LogTypes.HWCPatients,
LogFrom = short.Parse(model.LoginRoleId.ToString()),
LogDate = DateTime.UtcNow,
LocationId = (int)model.LocationId,
LogDescription = $" {model.CreatedByName} has added new <b>HWC</b> type : <strong>{model.HWCName}</strong>."
};
await this.auditLogServices.LogAsync(auditLogModel);
}
}
catch (Exception)
{
// ignore
}
return this.Success(response);
}
/// <summary>
/// Inserts the hoc asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="location">The location.</param>
/// <returns></returns>
[HttpPost]
[Route("update")]
public async Task<ActionResult> UpdateHocAsync([FromBody] HwcPatientModel model, [FromHeader] LocationHeader location)
{
model = (HwcPatientModel)EmptyFilter.Handler(model);
model.LocationId = !string.IsNullOrEmpty(location.LocationId) ? int.Parse(location.LocationId) : (int?)null;
var response = await this.hocPatientService.UpdateAsync(model);
try
{
if (response > 0)
{
var auditLogModel = new AuditLogModel
{
AccountId = model.CreatedBy,
LogTypeId = (int)LogTypes.HWCPatients,
LogFrom = short.Parse(model.LoginRoleId.ToString()),
LogDate = DateTime.UtcNow,
LocationId = (int)model.LocationId,
LogDescription = $" {model.CreatedByName} has updated the <b>HWC</b> type to : <strong>{model.HWCName}</strong>."
};
await this.auditLogServices.LogAsync(auditLogModel);
}
}
catch (Exception)
{
// ignore
}
return this.Success(response);
}
/// <summary>
/// Fetches all asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="location">The location.</param>
/// <returns></returns>
[HttpPost]
[Route("fetch-all")]
public async Task<ActionResult> FetchAllAsync([FromBody] HwcPatientModel model, [FromHeader] LocationHeader location)
{
model ??= new HwcPatientModel();
model.LocationId = !string.IsNullOrEmpty(location.LocationId) ? int.Parse(location.LocationId) : (int?)null;
var response = await this.hocPatientService.FetchAllAsync(model);
return this.Success(response);
}
/// <summary>
/// Deletes the asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <returns></returns>
[HttpPost]
[Route("delete")]
public async Task<ActionResult> DeleteAsync([FromBody] HwcPatientModel model, [FromHeader] LocationHeader location)
{
try
{
model = (HwcPatientModel)EmptyFilter.Handler(model);
var response = await this.hocPatientService.DeleteAsync(model);
try
{
if (response > 0)
{
model.LocationId = !string.IsNullOrEmpty(location.LocationId) ? int.Parse(location.LocationId) : (int?)null;
var auditLogModel = new AuditLogModel
{
AccountId = model.CreatedBy,
LogTypeId = (int)LogTypes.HWCPatients,
LogFrom = short.Parse(model.LoginRoleId.ToString()),
LogDate = DateTime.UtcNow,
LocationId = (int)model.LocationId,
LogDescription = $" {model.CreatedByName} has deleted the <b>HWC</b> <strong>{model.HWCName}</strong>."
};
await this.auditLogServices.LogAsync(auditLogModel);
}
}
catch (Exception)
{
// ignore
}
return this.Success(response);
}
catch (Exception)
{
return this.Success(-3);
}
}
}
}
\ No newline at end of file
namespace Hims.Api.Controllers
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Domain.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Npgsql;
using Shared.DataFilters;
using Shared.EntityModels;
using Shared.UserModels.Filters;
using Utilities;
using Hims.Shared.Library.Enums;
using Hims.Api.Models;
/// <inheritdoc />
[Authorize]
[Route("api/icd-code")]
[Consumes("application/json")]
[Produces("application/json")]
public class IcdCodeController : BaseController
{
/// <summary>
/// The icdCode services.
/// </summary>
private readonly IIcdService icdCodeService;
/// <summary>
/// The audit log services.
/// </summary>
private readonly IAuditLogService auditLogServices;
/// <inheritdoc />
public IcdCodeController(IIcdService icdCodeService, IAuditLogService auditLogServices) { this.icdCodeService = icdCodeService; this.auditLogServices = auditLogServices; }
/// <summary>
/// The fetch ICDCodes.
/// </summary>
/// <param name="model">
/// The ICDCode filter model.
/// </param>
/// <returns>
/// The list of ICDCodes.
/// </returns>
/// <remarks>
/// ### REMARKS ###
/// The following codes are returned
/// - 200 - List of ICDCodes.
/// - 500 - Problem with Server side code.
/// </remarks>
[HttpPost]
[Route("fetch")]
[ProducesResponseType(typeof(List<ICDCodeModel>), 200)]
[ProducesResponseType(500)]
public async Task<ActionResult> FetchAsync([FromBody]IcdCodeFilterModel model)
{
model = (IcdCodeFilterModel)EmptyFilter.Handler(model);
var icdCodes = await this.icdCodeService.FetchAsync(model);
return this.Success(icdCodes);
}
/// <summary>
/// The add icd codes.
/// </summary>
/// <param name="model">
/// The model.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
/// <remarks>
/// ### REMARKS ###
/// The following codes are returned
/// - 200 - ICDCode added successfully.
/// - 409 - ICDCode already exist.
/// - 500 - Problem with Server side code.
/// </remarks>
[HttpPost]
[Route("add")]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(409)]
[ProducesResponseType(500)]
public async Task<ActionResult> AddAsync([FromBody]ICDCodeModel model, [FromHeader] LocationHeader header)
{
model = (ICDCodeModel)EmptyFilter.Handler(model);
var response = await this.icdCodeService.AddAsync(model);
switch (response)
{
case -1:
return this.Conflict("Given ICDCode name has already been exists with us.");
case 0:
return this.ServerError();
}
var auditLogModel = new AuditLogModel
{
AccountId = model.CreatedBy,
LogTypeId = (int)LogTypes.ICDCodes,
LogFrom = (int)AccountType.Administrator,
LogDate = DateTime.UtcNow,
LogDescription = $"{model.Code} ICDCode has been added.",
LocationId= Convert.ToInt32(header.LocationId)
};
await this.auditLogServices.LogAsync(auditLogModel);
return this.Success("ICDCode has been added successfully.");
}
/// <summary>
/// The update ICDCode.
/// </summary>
/// <param name="model">
/// The model.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
/// <remarks>
/// ### REMARKS ###
/// The following codes are returned
/// - 200 - ICDCode updated successfully.
/// - 409 - ICDCode already exist.
/// - 500 - Problem with Server side code.
/// </remarks>
[HttpPut]
[Route("update")]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(409)]
[ProducesResponseType(500)]
public async Task<ActionResult> UpdateAsync([FromBody]ICDCodeModel model, [FromHeader] LocationHeader header)
{
model = (ICDCodeModel)EmptyFilter.Handler(model);
var response = await this.icdCodeService.UpdateAsync(model);
switch (response)
{
case -1:
return this.Conflict("Given ICDCode name has already been exists with us.");
case 0:
return this.ServerError();
}
var auditLogModel = new AuditLogModel
{
AccountId = model.ModifiedBy,
LogTypeId = (int)LogTypes.ICDCodes,
LogFrom = (int)AccountType.Administrator,
LogDate = DateTime.UtcNow,
LogDescription = $"{model.Code} ICDCode has been updated successfully.",
LocationId= Convert.ToInt32(header.LocationId)
};
await this.auditLogServices.LogAsync(auditLogModel);
return this.Success("ICDCode has been updated successfully.");
}
/// <summary>
/// The delete ICDCode.
/// </summary>
/// <param name="model">
/// The model.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
/// <remarks>
/// ### REMARKS ###
/// The following codes are returned
/// - 200 - ICDCode deleted successfully.
/// - 409 - ICDCode can not be deleted.
/// - 500 - Problem with Server side code.
/// </remarks>
[HttpPost]
[Route("delete")]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(409)]
[ProducesResponseType(500)]
public async Task<ActionResult> DeleteAsync([FromBody]ICDCodeModel model, [FromHeader] LocationHeader header)
{
try
{
model = (ICDCodeModel)EmptyFilter.Handler(model);
var response = await this.icdCodeService.DeleteAsync(model.ICDCodeId);
var responseProviderEncounter = await this.icdCodeService.updateProviderEncounterAsync(model.ICDCodeId);
if (response == 0)
{
return this.ServerError();
}
var auditLogModel = new AuditLogModel
{
AccountId = model.ModifiedBy,
LogTypeId = (int)LogTypes.ICDCodes,
LogFrom = (int)AccountType.Administrator,
LogDate = DateTime.UtcNow,
LogDescription = $"{model.Code} ICDCode has been deleted successfully.",
LocationId= Convert.ToInt32(header.LocationId)
};
await this.auditLogServices.LogAsync(auditLogModel);
return this.Success("ICDCode has been deleted successfully.");
}
catch (NpgsqlException)
{
return this.ServerError();
}
}
}
}
\ No newline at end of file
namespace Hims.Api.Controllers
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Domain.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Npgsql;
using Shared.DataFilters;
using Shared.EntityModels;
using Shared.UserModels.Filters;
using Utilities;
using Hims.Api.Models.Icons;
using Hims.Domain.Helpers;
using Hims.Shared.Library.Enums;
/// <inheritdoc />
[Authorize]
[Route("api/icons")]
[Consumes("application/json")]
[Produces("application/json")]
public class IconsController : BaseController
{
/// <summary>
/// The icon service.
/// </summary>
private readonly IIconService iconService;
/// <summary>
/// The document helper.
/// </summary>
private readonly IDocumentHelper documentHelper;
/// <inheritdoc />
public IconsController(IIconService iconService, IDocumentHelper documentHelper)
{
this.iconService = iconService;
this.documentHelper = documentHelper;
}
/// <summary>
/// The add icons async.
/// </summary>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
[HttpPost]
[AllowAnonymous]
[Route("add-icons")]
[Consumes("multipart/form-data")]
[Produces("application/json")]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(417)]
[ProducesResponseType(500)]
public async Task<ActionResult> AddIconsAsync()
{
var files = this.Request.Form.Files;
if (files.Count > 0)
{
var contentTypes = this.documentHelper.FetchContentTypes().ToList();
if (!ListFilter.ContainsAll(contentTypes, files.Select(m => m.ContentType).Distinct()))
{
return this.Failed($"Only {string.Join(", ", contentTypes)} files are allowed.");
}
foreach (var file in files)
{
var fileName = $"I_{DateTime.Now:MM-dd-yyyy}_{file.FileName}";
var url = await this.documentHelper.UploadAttachmentsAsync(file, "vs", "Icons", fileName);
var fileUrl = $@"vs/{url}";
await this.iconService.AddIcons(new IconsModel { IconName = fileUrl });
}
return this.Success();
}
else
{
return this.BadRequest("Nothing to add.");
}
}
/// <summary>
/// The fetch icons async.
/// </summary>
/// <param name="model">
/// The model.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
[HttpPost]
[Route("fetch-icons")]
public async Task<ActionResult> FetchIconsAsync([FromBody] IconsRequestModel model)
{
model = (IconsRequestModel)EmptyFilter.Handler(model);
var response = await this.iconService.FetchIcons(model.PageSize, model.PageIndex);
foreach (var item in response)
{
if (item.Url != null)
{
var substring = item.Url.Substring(0, 9);
if (substring == "vs/Icons/")
{
item.Url = item.Url.Substring(9);
}
}
}
return this.Success(response);
}
/// <summary>
/// The delete icons.
/// </summary>
/// <param name="model">
/// The model.
/// </param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
[HttpPost]
[Route("delete")]
public async Task<ActionResult> DeleteIcons([FromBody] IconsModel model)
{
model = (IconsModel)EmptyFilter.Handler(model);
await this.documentHelper.DeleteAttachmentsAsync(model.IconName);
var response = await this.iconService.DeleteIconsAsync(model.IconsId);
return this.Success(response);
}
}
}
\ No newline at end of file
using Hims.Api.Models;
using Hims.Api.Utilities;
using Hims.Domain.Services;
using Hims.Shared.DataFilters;
using Hims.Shared.EntityModels;
using Hims.Shared.Library.Enums;
using Hims.Shared.UserModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hims.Api.Controllers
{
/// <inheritdoc />
[Authorize]
[Route("api/id-proof")]
[Consumes("application/json")]
[Produces("application/json")]
public class IdProofController : BaseController
{
/// <summary>
/// The idproof services.
/// </summary>
private readonly IIdProofService idProofService;
/// <summary>
/// The audit log services.
/// </summary>
private readonly IAuditLogService auditLogServices;
/// <inheritdoc />
public IdProofController(IIdProofService idProofService, IAuditLogService auditLogService)
{
this.idProofService = idProofService;
this.auditLogServices = auditLogService;
}
/// <summary>
/// Inserts the hoc asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="location">The location.</param>
/// <returns></returns>
[HttpPost]
[Route("add")]
public async Task<ActionResult> InsertAsync([FromBody] IdProofModel model, [FromHeader] LocationHeader header)
{
model = (IdProofModel)EmptyFilter.Handler(model);
var response = await this.idProofService.InsertAsync(model);
if (response > 0)
{
var auditLog = new AuditLogModel
{
AccountId = model.CreatedBy,
LogTypeId = (int)LogTypes.IdProof,
LogDate = DateTime.Now,
LogFrom = (short)model.LoginRoleId,
LogDescription = $"<b>{model.CreatedByName}<b> has added <b>Id Proof</b> of <strong>{model.IdProofName}</strong> successfully.",
LocationId =Convert.ToInt32(header.LocationId)
};
await this.auditLogServices.LogAsync(auditLog);
}
return this.Success(response);
}
[HttpPost]
[Route("update")]
public async Task<ActionResult> UpdateAsync([FromBody] IdProofModel model,[FromHeader]LocationHeader header)
{
model = (IdProofModel)EmptyFilter.Handler(model);
var response = await this.idProofService.UpdateAsync(model);
if (response > 0)
{
var auditLog = new AuditLogModel
{
AccountId = model.CreatedBy,
LogTypeId = (int)LogTypes.IdProof,
LogDate = DateTime.Now,
LogFrom = short.Parse(model.LoginRoleId.ToString()),
LogDescription = $"{model.CreatedByName} has updated <b>Id Proof</b> of <strong>{model.IdProofName}</strong> successfully.",
LocationId =Convert.ToInt32(header.LocationId)
};
await this.auditLogServices.LogAsync(auditLog);
}
return this.Success(response);
}
/// <summary>
/// Fetches all asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="location">The location.</param>
/// <returns></returns>
[HttpPost]
[Route("fetch-all")]
public async Task<ActionResult> FetchAsync([FromBody] IdProofModel model)
{
model = (IdProofModel)EmptyFilter.Handler(model);
var response = await this.idProofService.FetchAllAsync(model);
return this.Success(response);
}
/// <summary>
/// Fetches all asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="location">The location.</param>
/// <returns></returns>
[HttpPost]
[Route("fetch-active")]
public async Task<ActionResult> FetchActiveAsync([FromBody] IdProofModel model)
{
model = (IdProofModel)EmptyFilter.Handler(model);
var response = await this.idProofService.FetchActiveAllAsync(model);
return this.Success(response);
}
[HttpPost]
[Route("modify-status")]
[ProducesResponseType(typeof(string), 200)]
[ProducesResponseType(409)]
[ProducesResponseType(500)]
public async Task<ActionResult> ModifyStatusAsync([FromBody] IdProofModel model,[FromHeader] LocationHeader header)
{
model = (IdProofModel)EmptyFilter.Handler(model);
var response = await this.idProofService.ActivateOrDeactivateTest(model);
if (response == 0)
{
return this.ServerError();
}
var auditLogModel = new AuditLogModel
{
AccountId = model.CreatedBy,
LogTypeId = (int)LogTypes.IdProof,
LogFrom = (short)model.LoginRoleId,
LogDate = DateTime.UtcNow.AddMinutes(330),
LogDescription = $@"<b>{model.ModifiedByName}</b> has {((bool)model.Active ? "Activated" : "Deactivated")} the IdProof <b> {model.IdProofName}</b> successfully",
LocationId =Convert.ToInt32(header.LocationId)
};
await this.auditLogServices.LogAsync(auditLogModel);
return this.Success(response);
}
}
}
using Hims.Api.Models;
using Hims.Api.Utilities;
using Hims.Domain.Helpers;
using Hims.Domain.Services;
using Hims.Shared.DataFilters;
using Hims.Shared.EntityModels;
using Hims.Shared.Library.Enums;
using Hims.Shared.UserModels;
using Hims.Shared.UserModels.Common;
using Hims.Shared.UserModels.InPatientsView;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Org.BouncyCastle.Asn1.IsisMtt.X509;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Hims.Api.Controllers
{
/// <inheritdoc />
[Authorize]
[Route("api/inpatients-view")]
public class InPatientsViewController : BaseController
{
/// <summary>
/// The working Hour services.
/// </summary>
private readonly IInPatientsViewService service;
/// <summary>
/// The AES helper.
/// </summary>
private readonly IAESHelper aesHelper;
/// <inheritdoc />
public InPatientsViewController(IInPatientsViewService service, IAESHelper aesHelper)
{
this.service = service;
this.aesHelper = aesHelper;
}
/// <summary>
/// Inserts the asynchronous.
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("fetch")]
public async Task<ActionResult> FetchAsync([FromBody] PayloadModel model)
{
var data = await this.service.FetchAsync(model);
foreach (var item in data)
{
item.EncryptedAdmissionId = this.aesHelper.Encode(item.AdmissionId.ToString());
}
return Success(new GenericResponse
{
Data = data,
Status = GenericStatus.Success,
});
}
/// <summary>
/// Inserts the asynchronous.
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("fetch-beds")]
public async Task<ActionResult> FetchBedsAsync([FromBody] PayloadBedsModel model)
{
var data = await this.service.FetchBeds(model);
return Success(new GenericResponse
{
Data = data,
Status = GenericStatus.Success,
});
}
}
}
namespace Hims.Api.Controllers
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Domain.Services;
using Hims.Api.Models;
using Hims.Domain.Entities;
using Hims.Domain.Entities.Enums;
using Hims.Shared.Library.Enums;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shared.DataFilters;
using Shared.EntityModels;
using Shared.UserModels;
using Shared.UserModels.OperationTheater;
using Shared.UserModels.PharmacyIndent;
using Utilities;
/// <summary>
/// The indent controller.
/// </summary>
[Authorize]
[Route("api/indent")]
[Consumes("application/json")]
[Produces("application/json")]
public class IndentController : BaseController
{
/// <summary>
/// The indent service.
/// </summary>
private readonly IIndentService indentService;
/// <summary>
/// The Inventory log services.
/// </summary>
private readonly IInventoryLogService inventoryLogServices;
/// <summary>
/// The general notification service.
/// </summary>
private readonly IGeneralNotificationService generalNotificationService;
/// <summary>
/// The web notification service
/// </summary>
private readonly IWebNotificationService webNotificationService;
/// <inheritdoc />
public IndentController(
IIndentService indentService,
IInventoryLogService inventoryLogServices,
IGeneralNotificationService generalNotificationService,
IWebNotificationService webNotificationService
)
{
this.indentService = indentService;
this.inventoryLogServices = inventoryLogServices;
this.generalNotificationService = generalNotificationService;
this.webNotificationService = webNotificationService;
}
/// <summary>
/// The create indent request.
/// </summary>
/// <param name="model">
/// The model.
/// </param>
/// <param name="location"></param>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
[HttpPost]
[Route("add-request")]
public async Task<ActionResult> CreateIndentRequest([FromBody] IndentRequestModel model, [FromHeader] LocationHeader location)
{
model = (IndentRequestModel)EmptyFilter.Handler(model);
model.LocationId = Convert.ToInt32(location.LocationId);
var response = await this.indentService.CreateIndentRequestAsync(model);
if (response > 0)
{
try
{
var iLogs = new InventoryLogModel
{
AccountId = model.CreatedBy,
InventoryLogTypeId = (int)InventoryLogTypes.Indent,
LogFrom = (short)model.RoleId,
LogDate = DateTime.UtcNow.AddMinutes(330),
LogDescription = $@"<b>{model.CreatedByName}</b> has raised Indent for department: <b>{model.InventoryDepartmentName}</b> from <b>Inventory</b>."
};
await this.inventoryLogServices.LogAsync(iLogs);
}
catch (Exception e)
{
//logs
}
}
return response > 0 ? this.Success(response) : this.ServerError();
}
/// <summary>
/// The fetch inventory indent request async.
/// </summary>
/// <returns>
/// The <see cref="Task"/>.
/// </returns>
[HttpPost]
[Route("fetch")]
public async Task<ActionResult> FetchInventoryIndentRequestAsync([FromBody] OTIndentModel model, [FromHeader] LocationHeader location)
{
model = (OTIndentModel)EmptyFilter.Handler(model);
model.LocationId = Convert.ToInt32(location.LocationId);
var response = await this.indentService.FetchInventoryIndentAsync(model);
return this.Success(response);
}
/// <summary>
/// Fetches the inventory indent detail asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <returns></returns>
[HttpPost]
[Route("fetch-detail")]
public async Task<ActionResult> FetchInventoryIndentDetailAsync([FromBody] OTIndentModel model)
{
model = (OTIndentModel)EmptyFilter.Handler(model);
if (model.IndentHeaderId == 0)
{
return this.BadRequest("Something wrong with supplied parameter.Please check..!!");
}
var response = await this.indentService.FetchInventoryIndentDetailAsync(model);
return this.Success(response);
}
/// <summary>
/// The delete indent request async.
/// </summary>
/// <param name="id">
/// The id
/// </param>
/// <returns>
/// The <see cref="Task"/>
/// </returns>
[HttpGet]
[Route("delete")]
public async Task<ActionResult> DeleteIndentRequestAsync(int id)
{
var response = await this.indentService.DeleteIndentRequestAsync(id);
return this.Success(response);
}
/// <summary>
/// Adds the pharmacy department indent asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <returns></returns>
[HttpPost]
[Route("add-pharmacy-department-indent")]
public async Task<ActionResult> AddPharmacyDepartmentIndentAsync([FromBody] PharmacyDepartmentIndentHeaderModel model)
{
model = (PharmacyDepartmentIndentHeaderModel)EmptyFilter.Handler(model);
var response = await this.indentService.AddPharmacyDepartmentIndentAsync(model);
try
{
var roles = (await this.webNotificationService.GetAllRoles()).ToList();
var getRolesToNotify = roles.Where(r => r.RoleName.ToLower().Contains("pharm"));
var getAdmins = roles.Where(r => r.RoleName.ToLower().Contains("admin"));
var finalRoleModel = new List<RoleModel>();
finalRoleModel.AddRange(getRolesToNotify.ToList());
finalRoleModel.AddRange(getAdmins.ToList());
var notification = new GeneralNotificationModel
{
CreatedBy = model.CreatedBy,
CreatedDate = model.CreatedDate,
IsPriority = true,
Message = " has created pharmacy indent",
ModulesMasterId = (int)ModulesMasterType.Pharmacy,
ReferenceId = response,
ForRoles = string.Join(",", finalRoleModel.Select(r => r.RoleId)),
WebNotificationLogTypeId = (int)WebNotificationLogType.View,
RedirectUrl = "app/dashboard"
};
await this.generalNotificationService.AddGeneralNotificationAsync(notification);
}
catch (Exception)
{
// ignore
}
return this.Success(response);
}
/// <summary>
/// Fetches the pharmacy department asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <param name="location"></param>
/// <returns></returns>
[HttpPost]
[Route("fetch-pharmacy-department-indent")]
public async Task<ActionResult> FetchPharmacyDepartmentIndentAsync([FromBody] PharmacyDepartmentIndentHeaderModel model, [FromHeader] LocationHeader location)
{
model ??= new PharmacyDepartmentIndentHeaderModel() ;
if (!string.IsNullOrEmpty(location.LocationId))
{
model.LocationId = Convert.ToInt32(location.LocationId);
}
var response = await this.indentService.FetchPharmacyDepartmentIndentAsync(model);
return this.Success(response);
}
/// <summary>
/// Fetches the pharmacy department indent detail asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <returns></returns>
[HttpPost]
[Route("fetch-pharmacy-department-indent-detail")]
public async Task<ActionResult> FetchPharmacyDepartmentIndentDetailAsync([FromBody] PharmacyDepartmentIndentDetailModel model)
{
model = (PharmacyDepartmentIndentDetailModel)EmptyFilter.Handler(model);
var response = await this.indentService.FetchIndentDetailsAsync(model);
return this.Success(response);
}
/// <summary>
/// Approves the pharmacy department indent asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <returns></returns>
[HttpPost]
[Route("approve-pharmacy-department-indent")]
public async Task<ActionResult> ApprovePharmacyDepartmentIndentAsync([FromBody] PharmacyDepartmentIndentHeaderModel model)
{
model = (PharmacyDepartmentIndentHeaderModel)EmptyFilter.Handler(model);
var response = await this.indentService.ApprovePharmacyDepartmentIndentAsync(model);
return this.Success(response);
}
}
}
namespace Hims.Api.Controllers
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Domain.Services;
using Hims.Api.Models;
using Hims.Domain.Entities;
using Hims.Domain.Entities.Enums;
using Hims.Shared.Library.Enums;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Shared.DataFilters;
using Shared.EntityModels;
using Shared.UserModels;
using Shared.UserModels.Vendors;
using Utilities;
/// <summary>
/// The vendor quotation controller.
/// </summary>
[Authorize]
[Route("api/vendor-quotation")]
[Consumes("application/json")]
[Produces("application/json")]
public class InitialVendorQuotationController : BaseController
{
/// <summary>
/// The quotation service
/// </summary>
private readonly IQuotationService quotationService;
/// <inheritdoc />
public InitialVendorQuotationController(
IQuotationService quotationService
)
{
this.quotationService = quotationService;
}
/// <summary>
/// Called when add incoming quotation asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <returns></returns>
[HttpPost]
[Route("add-incoming-quotation")]
public async Task<ActionResult> OnAddIncomingQuotationAsync([FromBody] IncomingQuotationHeaderModel model)
{
model = (IncomingQuotationHeaderModel)EmptyFilter.Handler(model);
if(model.Products.Count == 0)
{
return BadRequest("No Product found.");
}
var response = await this.quotationService.OnIncomingQuotationAsync(model);
return this.Success(response);
}
/// <summary>
/// Fetches the incoming quotation asynchronous.
/// </summary>
/// <param name="model">The model.</param>
/// <returns></returns>
[HttpPost]
[Route("fetch-incoming-quotation")]
public async Task<ActionResult> FetchIncomingQuotationAsync([FromBody] IncomingQuotationHeaderModel model)
{
model ??= new IncomingQuotationHeaderModel();
var response = await this.quotationService.FetchIncomingQuotationAsync(model);
return this.Success(response);
}
/// <summary>
/// Deletes the incoming quotation asynchronous.
/// </summary>
/// <param name="id">The identifier.</param>
/// <returns></returns>
[HttpGet]
[Route("delete-quotation")]
public async Task<ActionResult> DeleteIncomingQuotationAsync(long id)
{
return this.Success(await this.quotationService.DeleteQuotationAsync(id));
}
/// <summary>
/// Accepts the quotation asynchronous.
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="createdBy">The created by.</param>
/// <returns></returns>
[HttpGet]
[Route("accept-quotation")]
public async Task<ActionResult> AcceptQuotationAsync(long id, int createdBy)
{
return this.Success(await this.quotationService.OnAcceptQuotation(id, createdBy));
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment