aboutsummaryrefslogtreecommitdiffstats
path: root/code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2022-11-14 04:37:56 +0100
committerivarlovlie <git@ivarlovlie.no>2022-11-14 04:37:56 +0100
commit11be5df857a74fa8ee1c9dcb661a293ed9f09536 (patch)
treee32055c5e2770234193ef7d4e82306746c31f78e /code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs
parent47004bfcf8ef72556d8227bbce7dd5c06dc73040 (diff)
downloadgreatoffice-11be5df857a74fa8ee1c9dcb661a293ed9f09536.tar.xz
greatoffice-11be5df857a74fa8ee1c9dcb661a293ed9f09536.zip
feat: Remove old time tracker models, routes and entities
Diffstat (limited to 'code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs')
-rw-r--r--code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs44
1 files changed, 0 insertions, 44 deletions
diff --git a/code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs b/code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs
deleted file mode 100644
index d6106aa..0000000
--- a/code/api/src/Endpoints/V1/Labels/CreateLabelRoute.cs
+++ /dev/null
@@ -1,44 +0,0 @@
-namespace IOL.GreatOffice.Api.Endpoints.V1.Labels;
-
-public class CreateLabelRoute : RouteBaseSync.WithRequest<TimeLabel.TimeLabelDto>.WithActionResult<TimeLabel.TimeLabelDto>
-{
- private readonly MainAppDatabase _database;
-
- public CreateLabelRoute(MainAppDatabase database) {
- _database = database;
- }
-
- /// <summary>
- /// Create a time entry label.
- /// </summary>
- /// <param name="labelTimeLabelDto"></param>
- /// <returns></returns>
- [ApiVersion(ApiSpecV1.VERSION_STRING)]
- [BasicAuthentication(AppConstants.TOKEN_ALLOW_CREATE)]
- [HttpPost("~/v{version:apiVersion}/labels/create")]
- public override ActionResult<TimeLabel.TimeLabelDto> Handle(TimeLabel.TimeLabelDto labelTimeLabelDto) {
- var duplicate = _database.TimeLabels
- .Where(c => c.UserId == LoggedInUser.Id)
- .Any(c => c.Name.Trim() == labelTimeLabelDto.Name.Trim());
- if (duplicate) {
- var label = _database.TimeLabels
- .Where(c => c.UserId == LoggedInUser.Id)
- .SingleOrDefault(c => c.Name.Trim() == labelTimeLabelDto.Name.Trim());
-
- if (label != default) {
- return Ok(label.AsDto);
- }
- }
-
- var newLabel = new TimeLabel(LoggedInUser) {
- Name = labelTimeLabelDto.Name.Trim(),
- Color = labelTimeLabelDto.Color
- };
- newLabel.SetOwnerIds(LoggedInUser.Id);
-
- _database.TimeLabels.Add(newLabel);
- _database.SaveChanges();
- labelTimeLabelDto.Id = newLabel.Id;
- return Ok(labelTimeLabelDto);
- }
-} \ No newline at end of file