Пример #1
0
        private void UpdateInvitees(Event info, IEnumerable <int> newList)
        {
            var oldInvites = _db.EventInvitees.Where(e => e.EventId == info.EventId).ToList();
            var oldList    = oldInvites.Select(i => i.UserId).ToList();

            foreach (var newId in newList)
            {
                if (!oldList.Contains(newId))
                {
                    var user = _db.Users.Find(newId);
                    var map  = new EventInvitee
                    {
                        UserId   = user.UserId,
                        UserName = user.FullName,
                        EventId  = info.EventId
                    };
                    _db.EventInvitees.Add(map);
                }
            }
            foreach (var old in oldInvites)
            {
                if (!newList.Contains(old.UserId))
                {
                    _db.Entry(old).State = System.Data.EntityState.Deleted;
                }
            }
            info.Invitees = null;
        }
		public object Deserialize(JsonValue json, JsonMapper mapper)
		{
			EventInvitee album = null;
			if ( json != null && !json.IsNull )
			{
				album = new EventInvitee();
				album.ID         = json.ContainsName("id"  ) ? json.GetValue<string>("id"  ) : String.Empty;
				album.Name       = json.ContainsName("name") ? json.GetValue<string>("name") : String.Empty;
				album.RsvpStatus = RsvpStatusDeserializer(json.GetValue("rsvp_status"));
			}
			return album;
		}
Пример #3
0
        public JsonResult UpdateStatus(EventInvitee model)
        {
            _srv.UpdateStatus(model.EventId, model.Status);
            var evnt   = _db.Events.Include(e => e.Invitees).Single(e => e.EventId == model.EventId);
            var result = new
            {
                gnCnt = evnt.GoingCnt,
                ngCnt = evnt.NotGoingCnt,
                mbCnt = evnt.MayBeCnt,
            };

            return(Json(result));
        }
        public object Deserialize(JsonValue json, JsonMapper mapper)
        {
            EventInvitee album = null;

            if (json != null && !json.IsNull)
            {
                album            = new EventInvitee();
                album.ID         = json.ContainsName("id") ? json.GetValue <string>("id") : String.Empty;
                album.Name       = json.ContainsName("name") ? json.GetValue <string>("name") : String.Empty;
                album.RsvpStatus = RsvpStatusDeserializer(json.GetValue("rsvp_status"));
            }
            return(album);
        }
Пример #5
0
        public void UpdateStatus(int id, InviteStatusTypes status)
        {
            var user    = _db.Users.Find(CurrUserId);
            var invitee = _db.EventInvitees.SingleOrDefault(i => i.UserId == user.UserId && i.EventId == id);

            if (invitee == null)
            {
                invitee = new EventInvitee
                {
                    UserId   = user.UserId,
                    UserName = user.FullName,
                    Status   = status,
                    EventId  = id
                };
                _db.EventInvitees.Add(invitee);
            }
            else
            {
                invitee.Status           = status;
                invitee.Date             = DateTime.UtcNow;
                _db.Entry(invitee).State = System.Data.EntityState.Modified;
            }
            _db.SaveChanges();
        }