示例#1
0
        public Person getPerson(string login)
        {
            if (login == null)
            {
                log.Error("Empty user");
                throw new Exception("Empty user");
            }
            try
            {
                using (var db = new StorageContext())
                {
                    if (db.People.Where(p => p.UserID.Equals(login)).ToList().Count == 0)
                    {
                        var newPerson = new Person {
                            PersonID = Guid.NewGuid(), FirstName = "Adam", LastName = "Test", UserID = login
                        };
                        this.login = db.People.Add(newPerson);
                        db.SaveChanges();
                        log.Info("Add new user: "******" with id: " + this.login.PersonID);
                    }
                    else
                    {
                        this.login = db.People.Where(p => p.UserID.Equals(login)).First();
                    }

                    log.Info("User Loged: " + this.login.UserID);
                }
                return(this.login);
            }
            catch (ArgumentNullException ANE)
            {
                log.Error("User " + login + "can't be load:" + ANE);
                throw ANE;
            }
        }
示例#2
0
 public void updateAppointment(Appointment st)
 {
     using (var db = new StorageContext())
     {
         var original = db.Appointments.Find(st.AppointmentID);
         if (original != null && Encoding.ASCII.GetString(original.timestamp) == Encoding.ASCII.GetString(st.timestamp))
         {
             original.Title           = st.Title;
             original.AppointmentDate = st.AppointmentDate;
             original.StartTime       = st.StartTime;
             original.EndTime         = st.EndTime;
             original.Description     = st.Description;
             try
             {
                 db.SaveChanges();
             }
             catch (Exception E)
             {
                 log.Error("Message did not create becouse of: " + E);
                 throw E;
             }
         }
         else
         {
             throw new Exception("Your appointment version is not actualy");
         }
     }
 }
示例#3
0
 public void deleteAppointment(Appointment st)
 {
     using (var db = new StorageContext())
     {
         var original = db.Appointments.Find(st.AppointmentID);
         if (original != null && Encoding.ASCII.GetString(original.timestamp) == Encoding.ASCII.GetString(st.timestamp))
         {
             var at = db.Attendances.First(a => a.AppointmentID == st.AppointmentID);
             db.Attendances.Remove(at);
             try
             {
                 db.SaveChanges();
             }
             catch (Exception E)
             {
                 log.Error("Message did not create becouse of: " + E);
                 throw E;
             }
         }
         else
         {
             throw new Exception("Your appointment version is not actualy");
         }
     }
 }
示例#4
0
 public void updateAppointment(Appointment st)
 {
     using (var db = new StorageContext())
     {
         var original = db.Appointments.Find(st.AppointmentId);
         if (original != null && original.Version == st.Version)
         {
             original.Title           = st.Title;
             original.AppointmentDate = st.AppointmentDate;
             original.StartTime       = st.StartTime;
             original.EndTime         = st.EndTime;
             original.Version         = st.Version + 1;
             try
             {
                 db.SaveChanges();
                 st.Version = st.Version + 1;
             }
             catch (Exception E)
             {
                 log.Error("Message did not create becouse of: " + E);
                 throw E;
             }
         }
         else
         {
             throw new Exception("Your appointment version is not actualy");
         }
     }
 }
示例#5
0
        public Guid createAppointment(string title, string description, DateTime date, TimeSpan startDate, TimeSpan endDate, Person user)
        {
            using (var db = new StorageContext())
            {
                var Appointment = new Appointment
                {
                    AppointmentID   = Guid.NewGuid(),
                    Title           = title,
                    Description     = description,
                    AppointmentDate = date,
                    StartTime       = startDate,
                    EndTime         = endDate
                };

                var id = db.Appointments.Add(Appointment);

                db.Attendances.Add(new Attendance()
                {
                    AttendanceID = Guid.NewGuid(), PersonID = user.PersonID, AppointmentID = id.AppointmentID
                });
                try
                {
                    db.SaveChanges();
                    log.Info("Create new appointment: " + id.AppointmentID);
                    return(Appointment.AppointmentID);
                }
                catch (Exception E)
                {
                    log.Error("Message did not create becouse of: " + E);
                    throw E;
                }
            }
        }
示例#6
0
 public void createAppointment(string title, DateTime startDate, DateTime endDate)
 {
     using (var db = new StorageContext())
     {
         var Appointment = new Appointment
         {
             Title           = title,
             AppointmentDate = startDate.Date,
             StartTime       = startDate,
             EndTime         = endDate,
             Version         = 1,
             Attendances     = new List <Attendance>()
         };
         db.Appointments.Add(Appointment);
         try
         {
             db.SaveChanges();
         }
         catch (Exception E)
         {
             log.Error("Message did not create becouse of: " + E);
             throw E;
         }
     }
 }
示例#7
0
 public void CreatePerson(string firstName, string lastName, string userId)
 {
     using (var db = new StorageContext()) {
         var person = new Person
         {
             PersonId  = Guid.NewGuid(),
             FirstName = firstName,
             LastName  = lastName,
             UserID    = userId,
         };
         db.Persons.Add(person);
         db.SaveChanges();
     }
 }
示例#8
0
        public void DeleteAppointment(Appointment st)
        {
            using (var db = new StorageContext())
            {
                var original = db.Appointments.Find(st.AppointmentId);
                if (original != null)
                {
                    original.Attendances.ToList().ForEach(attendance => db.Attendances.Remove(attendance));

                    db.Appointments.Remove(original);
                    db.SaveChanges();
                }
            }
        }
示例#9
0
        public Appointment CreateAppointment(string title, DateTime startTime, DateTime endTime)
        {
            using (var db = new StorageContext())
            {
                var appointment = new Appointment
                {
                    AppointmentId = Guid.NewGuid(),
                    Title         = title,
                    StartTime     = startTime,
                    EndTime       = endTime
                };
                db.Appointments.Add(appointment);

                db.SaveChanges();
                return(appointment);
            }
        }
示例#10
0
        public Attendance CreateAttendance(Appointment appointment, Person person)
        {
            using (var db = new StorageContext())
            {
                var attendance = new Attendance
                {
                    AttendanceId  = Guid.NewGuid(),
                    Accepted      = true,
                    PersonId      = person.PersonId,
                    AppointmentId = appointment.AppointmentId,
                };
                db.Attendances.Add(attendance);

                db.SaveChanges();
                return(attendance);
            }
        }
示例#11
0
 public void UpdateAppointment(Appointment st)
 {
     using (var db = new StorageContext())
     {
         var original = db.Appointments.Find(st.AppointmentId);
         if (original != null)
         {
             db.Entry(original).OriginalValues["RowVersion"] = st.RowVersion;
             original.Title     = st.Title;
             original.StartTime = st.StartTime;
             original.EndTime   = st.EndTime;
             try
             {
                 db.SaveChanges();
             }
             catch (DbUpdateConcurrencyException e)
             {
                 string message = string.Format("Update of appointment \"{0}\" failed due to concurrent write!", st.Title);
                 log.Error(message, e);
                 throw new ConcurrentUpdateException(message);
             }
         }
     }
 }
示例#12
0
 public void deleteAppointment(Appointment st)
 {
     using (var db = new StorageContext())
     {
         var original = db.Appointments.Find(st.AppointmentId);
         if (original != null && original.Version == st.Version)
         {
             db.Appointments.Remove(original);
             try
             {
                 db.SaveChanges();
             }
             catch (Exception E)
             {
                 log.Error("Message did not create becouse of: " + E);
                 throw E;
             }
         }
         else
         {
             throw new Exception("Your appointment version is not actualy");
         }
     }
 }