Пример #1
0
        public HttpResponseMessage InviteUser(InviteUserModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var self        = HttpContext.Current.GetOwinContext().Authentication.User.Identity.Name;
                var selfUser    = dataContext.Users.SingleOrDefault(u => u.Username == self);
                var targetevent = dataContext.CalendarEvents.SingleOrDefault(e => e.EventId == model.EventId);
                var users       = model.UsersId.Split('_');
                foreach (var userId in users)
                {
                    var recvrGuid = Guid.Parse(userId);
                    var recvr     = dataContext.Users.SingleOrDefault(u => u.UserId == recvrGuid);
                    var ei        = new Event_Invite
                    {
                        InviteSender   = selfUser,
                        InviteReceiver = recvr,
                        InviteEvent    = targetevent,
                        Status         = 0
                    };

                    dataContext.EventInvites.Add(ei);
                }

                dataContext.SaveChanges();
                return(Request.CreateResponse(HttpStatusCode.Accepted, ""));
            }

            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "invalid data"));
        }
Пример #2
0
 public void InsertEvent_Invite(Event_Invite ei)
 {
     _context.EventInvites.Add(ei);
 }