Notes![what is notes.io? What is notes.io?](/theme/images/whatisnotesio.png)
![]() ![]() Notes - notes.io |
{
try
{
using var context = new ModelContext(UvamDBInterface.DbContextOptions);
var existingBaseline = context.Baselines
.Where(eb => eb.IdImpianto == idImpianto && eb.Data == data)
.ToList();
var existingUser = GetOperationUVAMDBInterface.GetUserByName(context, utente);
if (existingUser == null)
{
return "Errore: Utente non trovato.";
}
java
Copy code
var checkUser = context.UtenteImpiantos
.Where(ui => ui.IdUtente == existingUser.Id && ui.IdImpianto == idImpianto)
.ToList();
if (checkUser.Count <= 0)
{
return "Errore: L'Utente non ha i permessi per accedere all'Impianto.";
}
if (existingBaseline.Count > 0)
{
// update existing baseline
existingBaseline[0].Data = data;
existingBaseline[0].IdUtente = existingUser.Id;
existingBaseline[0].IdProfilo = null;
var baselineValorisToRemove = context.BaselineValoris.Where(bv => bv.IdBaseline == existingBaseline[0].Id).ToList();
foreach (var valore in baselineValorisToRemove)
{
context.BaselineValoris.Remove(valore);
}
context.SaveChanges();
int minute = 0;
decimal lastValue = 0;
foreach (var baselineValue in newBaseline)
{
int minuteDiff = baselineValue.m - minute;
for (int i = 0; i < minuteDiff; i += 15)
{
var baselineValues = new BaselineValori
{
IdBaseline = existingBaseline[0].Id,
Minuto = (byte)minute,
Valore = lastValue
};
context.BaselineValoris.Add(baselineValues);
minute += 15;
}
lastValue = baselineValue.v!;
}
for (int i = minute; i <= 1490; i += 15)
{
var baselineValues = new BaselineValori
{
IdBaseline = existingBaseline[0].Id,
Minuto = (byte)i,
Valore = lastValue
};
context.BaselineValoris.Add(baselineValues);
}
context.SaveChanges();
return existingBaseline[0].Id.ToString();
}
else
{
// create new baseline
var baseline = new Baseline
{
IdImpianto = idImpianto,
Data = data,
DataInserimento = data,
IdUtente = existingUser.Id
};
context.Baselines.Add(baseline);
context.SaveChanges();
csharp
Copy code
// loop through the new baseline values
int minute = 0;
decimal previousValue = 0;
foreach (var baselineValue in newBaseline)
{
int currentMinute = baselineValue.m;
// fill the missing minutes with the previous value
while (minute < currentMinute)
{
var baselineValues = new BaselineValori
{
IdBaseline = baseline.Id,
Minuto = (byte)minute,
Valore = previousValue
};
context.BaselineValoris.Add(baselineValues);
minute += 15;
}
// add the current value
var currentValore = (decimal)baselineValue.v!;
var currentBaselineValues = new BaselineValori
{
IdBaseline = baseline.Id,
Minuto = (byte)currentMinute,
Valore = currentValore
};
context.BaselineValoris.Add(currentBaselineValues);
minute += 15;
previousValue = currentValore;
}
// fill the remaining minutes with the last value
while (minute <= 1490)
{
var baselineValues = new BaselineValori
{
IdBaseline = baseline.Id,
Minuto = (byte)minute,
Valore = previousValue
};
context.BaselineValoris.Add(baselineValues);
minute += 15;
}
context.SaveChanges();
return baseline.Id.ToString();
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team