Added alarm notes
WIP Fanuc tool table WIP Siemens Active program fix
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using Step.Model.DatabaseModels;
|
||||
using Step.Model.DTOModels;
|
||||
using Step.Model.DTOModels.AlarmModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Entity;
|
||||
@@ -85,7 +85,7 @@ namespace Step.Database.Controllers
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
|
||||
public void InsertNewAlarmUser(List<AlarmUserModel> loggedUser)
|
||||
{
|
||||
dbCtx.AlarmUsers.AddRange(loggedUser);
|
||||
@@ -93,7 +93,7 @@ namespace Step.Database.Controllers
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
public AlarmsData GetAlarmsData(int pageSize)
|
||||
public DTOAlarmsData GetAlarmsData(int pageSize)
|
||||
{
|
||||
// Get page numbers
|
||||
int pagesNumbers = dbCtx.AlarmOccurrences.Count() / pageSize;
|
||||
@@ -102,17 +102,69 @@ namespace Step.Database.Controllers
|
||||
// Get first alarm date
|
||||
DateTime date = firstAlarm == null ? DateTime.Now : firstAlarm.TimeStamp;
|
||||
|
||||
return new AlarmsData
|
||||
return new DTOAlarmsData
|
||||
{
|
||||
Pages = pagesNumbers,
|
||||
FirstDate = date
|
||||
};
|
||||
}
|
||||
|
||||
public struct AlarmsData
|
||||
|
||||
public AlarmDescriptionsModel FindById(int id)
|
||||
{
|
||||
public int Pages;
|
||||
public DateTime FirstDate;
|
||||
return dbCtx
|
||||
.AlarmDescriptions
|
||||
.Where(x => x.AlarmId == id)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
#region NOTES
|
||||
|
||||
public AlarmNoteModel FindNoteById(int noteId)
|
||||
{
|
||||
return dbCtx
|
||||
.AlarmsNotes
|
||||
.Where(x => x.NoteId == noteId)
|
||||
.Include("User")
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public DTOAlarmNoteModel CreateNote(int userId, int alarmDescId, DTONewAlarmNoteModel newNote)
|
||||
{
|
||||
// Create model
|
||||
AlarmNoteModel note = new AlarmNoteModel()
|
||||
{
|
||||
Message = newNote.Message,
|
||||
DateTime = DateTime.Now,
|
||||
AlarmDescriptionId = alarmDescId,
|
||||
UserId = userId
|
||||
};
|
||||
// Add & save into database
|
||||
dbCtx.AlarmsNotes.Add(note);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
// Populate user data
|
||||
dbCtx.Entry(note).Reference(x => x.User).Load();
|
||||
dbCtx.Users.Attach(note.User);
|
||||
|
||||
return (DTOAlarmNoteModel)note;
|
||||
}
|
||||
|
||||
public DTOAlarmNoteModel UpdateNote(AlarmNoteModel note, DTONewAlarmNoteModel newNote)
|
||||
{
|
||||
note.Message = newNote.Message;
|
||||
dbCtx.SaveChanges();
|
||||
|
||||
return (DTOAlarmNoteModel)note;
|
||||
}
|
||||
|
||||
public void DeleteNote(int noteId)
|
||||
{
|
||||
AlarmNoteModel note = FindNoteById(noteId);
|
||||
dbCtx.AlarmsNotes.Remove(note);
|
||||
|
||||
dbCtx.SaveChanges();
|
||||
}
|
||||
|
||||
#endregion NOTES
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user