Beispiel #1
0
        public int AddUser(string firstName, string lastName)
        {
            var user = _ctx.Users.Create();

            user.FirstName = firstName;
            user.LastName  = lastName;
            _ctx.Users.Add(user);
            _ctx.SaveChanges();
            return(user.Id);
        }
Beispiel #2
0
        public bool AddUserToMeeting(int userId, int meetingId)
        {
            var newLink = new X_User_Meeting();

            newLink.MeetingId = meetingId;
            newLink.UserId    = userId;
            newLink.Active    = true;
            _ctx.X_User_Meeting.Add(newLink);
            return(_ctx.SaveChanges() > 0);
        }
Beispiel #3
0
        public bool SaveAttendance(int userId, int meetingId, bool isAttend, int recorderId)
        {
            if (meetingId <= 0 || userId <= 0 || recorderId <= 0)
            {
                return(false);
            }

            var attendencesForUserToday = _ctx.Attendances.Where(att => att.UserId == userId && att.MeetingId == meetingId && att.DateRecorded > DateTime.Today);

            if (!attendencesForUserToday.Any())
            {
                var attendance = new Attendance
                {
                    UserId       = userId,
                    MeetingId    = meetingId,
                    isAttend     = isAttend,
                    RecorderId   = recorderId,
                    LastUpdated  = DateTime.Now,
                    DateRecorded = DateTime.Now
                };
                _ctx.Attendances.Add(attendance);
            }
            else
            {
                foreach (var att in attendencesForUserToday)
                {
                    att.LastUpdated = DateTime.Now;
                    att.RecorderId  = recorderId;
                    att.isAttend    = isAttend;
                }
            }
            return(_ctx.SaveChanges() > 0);
        }
Beispiel #4
0
        public bool Update(User user)
        {
            if (user == null || user.Id <= 0)
            {
                return(false);
            }

            var olduser = _ctx.Users.FirstOrDefault(u => u.Id == user.Id);

            if (olduser == null)
            {
                return(false);
            }

            _ctx.Users.AddOrUpdate(user);
            _ctx.SaveChanges();

            return(true);
        }