public UserModel UserLogIn(string userName, string password) { Osebe_PDO tmpUsers = context.Osebe_PDO.Where(u => u.UporabniskoIme.CompareTo(userName) == 0 && u.Geslo.CompareTo(password) == 0).FirstOrDefault(); UserModel model = null; if (tmpUsers != null) { if (String.Compare(tmpUsers.UporabniskoIme, userName, false) != 0 && String.Compare(tmpUsers.Geslo, password) != 0) { throw new Exception("Napačna prijava! Ponovno vnesi geslo in uporabniško ime!"); } var allowLogin = tmpUsers.PDODostop.HasValue ? tmpUsers.PDODostop.Value : false; if (!allowLogin) { throw new Exception("Nimate dodeljenega dostopa do aplikacije. Obrnite se na administratorja"); } model = new UserModel(); model.ID = tmpUsers.OsebaID; model.firstName = tmpUsers.Ime; model.lastName = tmpUsers.Priimek; model.email = tmpUsers.Email; model.dateCreated = tmpUsers.ts.HasValue ? tmpUsers.ts.Value : DateTime.MinValue; model.Job = tmpUsers.DelovnoMesto; model.profileImage = tmpUsers.ProfileImage; model.RoleID = tmpUsers.VlogaID; model.Role = tmpUsers.Vloga_PDO.Koda; model.RoleName = tmpUsers.Vloga_PDO.Naziv; //model.Signature = tmpUsers.Podpis; } else { throw new Exception("Napačna prijava! Ponovno vnesi geslo in uporabniško ime!"); } return(model); }
public int SaveEmployee(EmployeeFullModel model, bool updateRecord = true) { try { Osebe_PDO record = new Osebe_PDO(); OsebeNadrejeni_PDO nadrejeni = new OsebeNadrejeni_PDO(); record.OsebaID = model.idOsebe; record.Naslov = model.Naslov; record.Email = model.Email; record.DelovnoMesto = model.DelovnoMesto; record.DatumZaposlitve = model.DatumZaposlitve; record.Ime = model.Ime; record.Priimek = model.Priimek; record.DatumRojstva = model.DatumRojstva; record.UporabniskoIme = model.UporabniskoIme; record.Geslo = model.Geslo; record.TelefonGSM = model.TelefonGSM; record.Zunanji = model.Zunanji; record.ProfileImage = model.ProfileImage; record.VlogaID = model.idVloga; record.tsUpdate = DateTime.Now; record.tsUpdateUserID = model.tsIDOsebe; record.ts = model.ts.Equals(DateTime.MinValue) ? (DateTime?)null : model.ts; record.tsIDOsebe = model.tsIDOsebe; record.PDODostop = model.PDODostop; record.EmailGeslo = model.EmailGeslo; record.EmailSifriranjeSSL = model.EmailSifriranjeSSL; record.EmailStreznik = model.EmailStreznik; record.EmailVrata = model.EmailVrata > 0 ? model.EmailVrata : (int?)null; record.Podpis = model.Podpis; record.PantheonUsrID = model.PantheonUsrID; if (record.OsebaID == 0) { record.ts = DateTime.Now; record.tsIDOsebe = model.tsIDOsebe; context.Osebe_PDO.Add(record); context.SaveChanges(); } else { if (updateRecord) { Osebe_PDO original = context.Osebe_PDO.Where(e => e.OsebaID == record.OsebaID).FirstOrDefault(); context.Entry(original).CurrentValues.SetValues(record); context.SaveChanges(); } } if (model.NadrejeniID > 0) { var supervisorExistForEmployee = context.OsebeNadrejeni_PDO.Where(osn => osn.OsebaID == record.OsebaID).FirstOrDefault(); nadrejeni.OsebaID = record.OsebaID; nadrejeni.NadrejeniID = model.NadrejeniID; if (supervisorExistForEmployee != null) { OsebeNadrejeni_PDO originalNadrejeni = context.OsebeNadrejeni_PDO.Where(e => e.OsebaID == record.OsebaID).FirstOrDefault(); nadrejeni.OsebeNadrejeniID = originalNadrejeni.OsebeNadrejeniID; context.Entry(originalNadrejeni).CurrentValues.SetValues(nadrejeni); } else { nadrejeni.ts = DateTime.Now; nadrejeni.tsIDosebe = model.tsIDOsebe; context.OsebeNadrejeni_PDO.Add(nadrejeni); } context.SaveChanges(); } return(record.OsebaID); } catch (Exception ex) { throw new Exception(ValidationExceptionError.res_08, ex); } }