Esempio n. 1
0
        public IHttpActionResult PutCalendar(int id, Calendar calendar)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != calendar.ID)
            {
                return(BadRequest());
            }

            db.Entry(calendar).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CalendarExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public ActionResult Create([Bind(Include = "ID,Title,StartDate,EndDate")] Calendar calendar)
        {
            if (ModelState.IsValid)
            {
                db.Calendars.Add(calendar);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(calendar));
        }
Esempio n. 3
0
 public void TestInitialize()
 {
     using (CalendarDBContext db = new CalendarDBContext())
     {
         expected = new List <Event>()
         {
             new Event()
             {
                 Name  = "Test Event 1",
                 Type  = db.Types.Where(t => t.Id == 2).First(),
                 Start = new DateTime(2017, 11, 9, 12, 0, 0),
                 End   = new DateTime(2017, 11, 9, 14, 0, 0)
             },
             new Event()
             {
                 Name  = "Test Event 2",
                 Type  = db.Types.Where(t => t.Id == 4).First(),
                 Start = new DateTime(2017, 11, 9, 9, 0, 0),
                 End   = new DateTime(2017, 11, 9, 10, 0, 0)
             }
         };
         db.Events.AddRange(expected);
         db.SaveChanges();
     }
 }
        //
        //Button, for adding events.
        //
        private void AddEventButton_Click(object sender, EventArgs e)
        {
            var          eventDate    = FindElement();
            var          events       = new Events();
            var          addEventForm = new AddEventForm();
            DialogResult result       = addEventForm.ShowDialog(this);

            try
            {
                if (result == DialogResult.OK)
                {
                    events.TextEvent  = addEventForm.EventTextBox.Text;
                    events.PlaceEvent = addEventForm.PlaceEventTextBox.Text;
                    events.StartDate  = addEventForm.dateTimePicker1.Value.ToShortTimeString();
                    events.EndDate    = addEventForm.dateTimePicker2.Value.ToShortTimeString();
                    events.IsEvent    = true;
                    events.Calendars  = eventDate;
                }
                db.DbEvents.Add(events);
                db.SaveChanges();
                MessageBox.Show("Событие добавлено!", "Уведомление", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 5
0
 public static bool SignUp(string username, string email, string password)
 {
     using (CalendarDBContext db = new CalendarDBContext())
     {
         var users = db.Users.Where(u => u.UserName == username || u.Mail.Address == email);
         if (users.Count() > 0)
         {
             return(false);
         }
         db.Users.Add(new User()
         {
             UserName = username,
             Password = password,
             Mail     = new EMailAddress()
             {
                 Address = email
             }
         });
         db.SaveChanges();
     }
     using (CalendarDBContext db = new CalendarDBContext())
     {
         List <User> tmp = db.Users.ToList();
         ActiveUser = db.Users.Where(u => u.UserName == username && u.Mail.Address == email && u.Password == password).First();
     }
     return(true);
 }
Esempio n. 6
0
 public static void EditPlans(List <Plan> newPlans)
 {
     using (CalendarDBContext db = new CalendarDBContext())
     {
         foreach (Plan plan in Plans)
         {
             if (newPlans.FindAll(p => p.Id == plan.Id).Count == 0)
             {
                 if (db.Plans.Where(p => p.Id == plan.Id).First().Users.Count <= 1)
                 {
                     db.Plans.Remove(db.Plans.Where(p => p.Id == plan.Id).First());
                 }
                 db.Users.Where(u => u.Id == ActiveUser.Id).First().Plans.Remove(db.Plans.Where(p => p.Id == plan.Id).First());
             }
         }
         foreach (Plan plan in newPlans)
         {
             if (Plans.FindAll(p => p.Id == plan.Id).Count == 0)
             {
                 db.Plans.Add(plan);
                 db.Users.Where(u => u.Id == ActiveUser.Id).First().Plans.Add(plan);
             }
         }
         db.SaveChanges();
     }
 }
Esempio n. 7
0
 public static void EditEvent(Event ev, string name, DataAccess.Type type, DateTime start, DateTime end, List <int> plansId, List <int> usersId, bool accepted)
 {
     using (CalendarDBContext db = new CalendarDBContext())
     {
         ev = db.Events.Where(e => e.Id == ev.Id).First();
         var plans = db.Plans;
         foreach (Plan plan in plans)
         {
             plan.Events.Remove(ev);
         }
         foreach (int id in plansId)
         {
             db.Plans.AsEnumerable().Where(p => p.Id == id).First().Events.Add(ev);
             ev.Plans.Add(db.Plans.AsEnumerable().Where(p => p.Id == id).First());
         }
         type = db.Types.Where(t => t.Id == type.Id).First();
         ev.Change(name, type, start, end);
         db.EventApprovals.Where(ea => ev.Id == ea.EventId && ActiveUser.Id == ea.UserId).First().Accepted = accepted;
         foreach (int id in usersId)
         {
             Event thisEvent = db.Events.Where(e => e.Id == ev.Id).First();
             User  user      = db.Users.Where(u => u.Id == id).First();
             db.EventApprovals.Add(new EventApproval()
             {
                 Event    = thisEvent,
                 User     = user,
                 Accepted = false
             });
             SendInvitationMail(thisEvent, user);
         }
         db.SaveChanges();
     }
 }
Esempio n. 8
0
 public static void AddEvent(string name, DataAccess.Type type, DateTime start, DateTime end, List <int> plansId, List <int> usersId, bool accepted)
 {
     using (CalendarDBContext db = new CalendarDBContext())
     {
         Event ev = new Event();
         ev.Owner = db.Users.Where(u => u.Id == ActiveUser.Id).First();
         foreach (int id in plansId)
         {
             db.Plans.AsEnumerable().Where(p => p.Id == id).First().Events.Add(ev);
             ev.Plans.Add(db.Plans.AsEnumerable().Where(p => p.Id == id).First());
         }
         type = db.Types.Where(t => t.Id == type.Id).First();
         ev.Change(name, type, start, end);
         db.Events.Add(ev);
         db.EventApprovals.Add(new EventApproval()
         {
             Event    = ev,
             User     = db.Users.Where(u => u.Id == ActiveUser.Id).First(),
             Accepted = accepted
         });
         foreach (int id in usersId)
         {
             User user = db.Users.Where(u => u.Id == id).First();
             db.EventApprovals.Add(new EventApproval()
             {
                 Event    = ev,
                 User     = user,
                 Accepted = false
             });
             SendInvitationMail(ev, user);
         }
         db.SaveChanges();
     }
 }
Esempio n. 9
0
 private void CalendarClosing(object sender, FormClosingEventArgs e)
 {
     using (CalendarDBContext db = new CalendarDBContext())
     {
         db.SaveChanges();
         db.Dispose();
     }
 }
Esempio n. 10
0
 public static void EditEmailAddress(string emailAddress)
 {
     using (CalendarDBContext db = new CalendarDBContext())
     {
         db.Users.Where(u => u.Id == ActiveUser.Id).First().Mail.Address = emailAddress;
         db.SaveChanges();
     }
 }
Esempio n. 11
0
 public static void DeleteEvent(Event ev)
 {
     using (CalendarDBContext db = new CalendarDBContext())
     {
         db.EventApprovals.RemoveRange(db.EventApprovals.Where(ea => ea.EventId == ev.Id && ea.UserId == ActiveUser.Id));
         if (!db.EventApprovals.Any(ea => ea.EventId == ev.Id && ea.UserId != ActiveUser.Id))
         {
             db.Events.Remove(db.Events.Where(e => e.Id == ev.Id).First());
         }
         db.SaveChanges();
     }
 }
Esempio n. 12
0
 public static void InviteToEvent(Event myEvent, int userId)
 {
     using (CalendarDBContext db = new CalendarDBContext())
     {
         Event thisEvent = db.Events.Where(e => e.Id == myEvent.Id).First();
         User  user      = db.Users.Where(u => u.Id == userId).First();
         db.EventApprovals.Add(new EventApproval()
         {
             Event    = myEvent,
             User     = user,
             Accepted = false
         });
         db.SaveChanges();
         SendInvitationMail(thisEvent, user);
     }
 }
Esempio n. 13
0
        public static void Initialize(CalendarDBContext dbContext)
        {
            if (dbContext.ScheduleData.Any())
            {
                return;   // DB has been seeded
            }

            dbContext.ScheduleData.AddRange(
                new ScheduleData
            {
                Subject   = "Ultimate1",
                StartTime = DateTime.Now,
                EndTime   = DateTime.Now.AddHours(1),
                RoomId    = "1"
            },

                new ScheduleData
            {
                Subject   = "Ultimate1",
                StartTime = DateTime.Now,
                EndTime   = DateTime.Now.AddHours(1),
                RoomId    = "2"
            },

                new ScheduleData
            {
                Subject   = "Ultimate1",
                StartTime = DateTime.Now,
                EndTime   = DateTime.Now.AddHours(1),
                RoomId    = "3"
            },

                new ScheduleData
            {
                Subject   = "Ultimate1",
                StartTime = DateTime.Now,
                EndTime   = DateTime.Now.AddHours(1),
                RoomId    = "4"
            }
                );
            dbContext.SaveChanges();
        }
        //
        //Method, for filling the calendar db.
        //
        private bool FillCalendar(CreateCalendarForm createForm, DialogResult result, CLibrary.Calendar calendar)//, List<CLibrary.Calendar> lcalendar)
        {
            if (result == DialogResult.OK)
            {
                StartDay = createForm.dateTimePicker1.Value;
                byte  _day      = Convert.ToByte(StartDay.Day);
                byte  _week     = (byte)StartDay.DayOfWeek;
                sbyte _month    = Convert.ToSByte(StartDay.Month);
                short _year     = Convert.ToInt16(StartDay.Year);
                byte  _interval = 12;

                void LeapYear() //Function.
                {
                    if (_year % 4 == 0 && _month < 3)
                    {
                        calendar.Months.ListNumMonth[1]++;
                    }
                    else if (_year % 4 != 0 && calendar.Months.ListNumMonth[1] == 29)
                    {
                        calendar.Months.ListNumMonth[1]--;
                    }
                }

                try
                {
                    LeapYear();
                    calendar.NumYear = _year;
                    for (byte j = 0; j < _interval; j++)
                    {
                        if (_month + j == 13)
                        {
                            _year++;
                            calendar.NumYear = _year;
                            LeapYear();
                            _month = (sbyte)(1 - j);
                        }
                        calendar.Months.NumMonth  = (byte)(_month + j);
                        calendar.Months.NameMonth = calendar.Months.ListNamesMonth[_month + j - 1];
                        for (byte k = 0; k < calendar.Months.ListNumMonth[_month + j - 1]; k++)
                        {
                            if (_week == 8)
                            {
                                _week = 1;
                            }
                            if (_day + k == calendar.Months.ListNumMonth[_month + j - 1] + 1)
                            {
                                _day = 1;
                                break;
                            }
                            calendar.Days.NumDay    = (byte)(_day + k);
                            calendar.Days.DayOfWeek = calendar.Days.ListDaysOfWeek[_week - 1];
                            if (createForm.ListRedDays.Contains(calendar.Days.DayOfWeek))
                            {
                                calendar.Days.RedDay = true;
                            }
                            else
                            {
                                calendar.Days.RedDay = false;
                            }
                            _week++;
                            db.Calendars.Add(calendar);
                            db.SaveChanges();
                        }
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(false);
        }
 //
 //Fail event.
 //
 private void CheckingTodayEvent_EventCheckingIsEvent(Events obj)
 {
     obj.IsEvent = false;
     db.SaveChanges();
 }
 public void Save()
 {
     _dbContext.SaveChanges();
 }