Пример #1
0
 public SaveResult<Event> SaveOrUpdate(Event t)
 {
     t.Id = 1;
     return new SaveResult<Event>(true, t);
 }
Пример #2
0
 public SaveResult<Event> Save(Event e)
 {
     return ServiceManager.Kernel.Get<IEventAccessor>().SaveOrUpdate(e);
 }
Пример #3
0
        public RedirectToRouteResult Update(EventModel model)
        {
            var oldEvent = ServiceManager.Kernel.Get<IEventManager>().GetById(model.Id);

            var newEvent = new Event()
            {
                Id = model.Id,
                StartTime = TimeZone.CurrentTimeZone.ToUniversalTime(new DateTime(model.StartTime.Ticks)),
                EndTime = TimeZone.CurrentTimeZone.ToUniversalTime(new DateTime(model.EndTime.Ticks)),
                Location = new Location()
                {
                    LocationName = model.LocationName,
                    Latitude = model.Latitude,
                    Longitude = model.Longitude
                },
                IsPrivate = model.IsPrivate,
                Title = model.Title,
                Description = model.Description,
                IsActive = model.IsActive,
                PollIsActive = model.PollIsActive,
                Owner = oldEvent.Owner,
                Votes = oldEvent.Votes
            };

            newEvent.Votes.Where(x => x.UserName.Equals(newEvent.Owner.DisplayName)).FirstOrDefault().Time = newEvent.StartTime;

            var result = ServiceManager.Kernel.Get<IEventManager>().Save(newEvent);

            if (result.Success)
            {
                return RedirectToAction("Index", new { eventId = result.Result.Id });
            }
            else
            {
                throw new Exception();
            }
        }
Пример #4
0
        public RedirectToRouteResult Create(EventModel model)
        {
            var user = ServiceManager.Kernel.Get<IUserManager>().GetByUserName(User.Identity.Name);

            var newEvent = new Event()
            {
                StartTime = TimeZone.CurrentTimeZone.ToUniversalTime(new DateTime(model.StartTime.Ticks)),
                EndTime = TimeZone.CurrentTimeZone.ToUniversalTime(new DateTime(model.EndTime.Ticks)),
                Location = new Location()
                {
                    LocationName = model.LocationName,
                    Latitude = model.Latitude,
                    Longitude = model.Longitude
                },
                IsPrivate = model.IsPrivate,
                Title = model.Title,
                Description = model.Description,
                IsActive = model.IsActive,
                StorageLocation = Backend.Accessors.FooCDNAccessor.StorageType.Tape,
                Owner = user,
                Posts = new List<Post>(),
                PollIsActive = model.PollIsActive
            };

            ServiceManager.Kernel.Get<IEventManager>().Save(newEvent);

            newEvent.Guests = new List<Invitation>()
            {
                new Invitation
                {
                    Guest = user,
                    GuestId = user.Id,
                    Response = ResponseType.Accepted
                }
            };

            ServiceManager.Kernel.Get<IEventManager>().Save(newEvent);

            newEvent.Votes = new List<Vote>()
            {
                new Vote
                {
                    Time = TimeZone.CurrentTimeZone.ToUniversalTime(new DateTime(model.StartTime.Ticks)),
                    UserName = user.DisplayName
                }
            };

            var result = ServiceManager.Kernel.Get<IEventManager>().Save(newEvent);

            if (model.ToFacebook)
            {
                ServiceManager.Kernel.Get<IFacebookManager>().PublishStatus(user, "Hey guys, I just created an event on Radabite at http://radabite.azurewebsites.net/Event?eventId=" + result.Result.Id + ", make sure to check it out!");
            }

            if (result.Success)
            {
                return RedirectToAction("Index", new { eventId = result.Result.Id });
            }
            else
            {
                throw new Exception();
            }
        }
Пример #5
0
        public RedirectToRouteResult Delete(EventModel model)
        {
            var newEvent = new Event()
            {
                Id = model.Id,
                StartTime = TimeZone.CurrentTimeZone.ToUniversalTime(new DateTime(model.StartTime.Ticks)),
                EndTime = TimeZone.CurrentTimeZone.ToUniversalTime(new DateTime(model.EndTime.Ticks)),
                Location = new Location()
                {
                    LocationName = model.LocationName,
                    Latitude = model.Latitude,
                    Longitude = model.Longitude
                },
                IsPrivate = model.IsPrivate,
                Title = model.Title,
                Description = model.Description,
                // Soft delete entry
                IsActive = false,
                Owner = model.Owner
            };

            var result = ServiceManager.Kernel.Get<IEventManager>().Save(newEvent);

            if (result.Success)
            {
                return RedirectToAction("Index", "Home");
            }
            else
            {
                throw new Exception();
            }
        }
Пример #6
0
 public SaveResult<Event> Save(Event t)
 {
     throw new NotImplementedException();
 }
Пример #7
0
        public SaveResult<Event> SaveOrUpdate(Event e)
        {
            using (var db = new Db())
            {
                if (e.Id != 0)
                {
                    var ev = db.Events.FirstOrDefault(x => x.Id == e.Id);
                    ev.Title = e.Title;
                    ev.StartTime = e.StartTime;
                    ev.EndTime = e.EndTime;
                    ev.IsPrivate = e.IsPrivate;
                    ev.Description = e.Description;
                    ev.Location = e.Location;
                    ev.FinishedGettingPosts = e.FinishedGettingPosts;
                    ev.IsActive = e.IsActive;
                    ev.PollIsActive = e.PollIsActive;
                    if (e.Guests != null)
                    {
                        foreach (var i in e.Guests)
                        {
                            i.Guest = db.Users.FirstOrDefault(x => x.Id == i.GuestId);
                            if (i.Id != 0)
                            {
                                db.Entry<Invitation>(i).State = EntityState.Modified;
                            }
                            else
                            {
                                ev.Guests.Add(i);
                                db.Entry<Invitation>(i).State = EntityState.Added;
                            }
                        }
                    }

                    if (e.Posts != null)
                    {
                        foreach (var p in e.Posts)
                        {
                            if (p.Id == 0)
                            {
                                p.From = db.Users.FirstOrDefault(x => x.Id == p.From.Id);
                                ev.Posts.Add(p);
                                db.Entry<Post>(p).State = EntityState.Added;
                                db.Entry<User>(p.From).State = EntityState.Modified;
                            }
                            if (p.Comments != null)
                            {
                                foreach (var c in p.Comments)
                                {
                                    if (c.Id == 0)
                                    {
                                        c.From = db.Users.FirstOrDefault(x => x.Id == c.From.Id);
                                        ev.Posts.FirstOrDefault(x => x.Id == p.Id).Comments.Add(c);
                                        db.Entry<Post>(c).State = EntityState.Added;
                                        db.Entry<User>(c.From).State = EntityState.Modified;
                                    }
                                }
                            }
                        }
                    }

                    if (e.Votes != null)
                    {
                        foreach (var v in e.Votes)
                        {
                            if (v.Id != 0)
                            {
                                db.Entry<Vote>(v).State = EntityState.Modified;
                            }
                            else
                            {
                                ev.Votes.Add(v);
                                db.Entry<Vote>(v).State = EntityState.Added;
                            }
                        }
                    }

                    db.Entry<Event>(ev).State = EntityState.Modified;
                    db.Entry<User>(ev.Owner).State = EntityState.Unchanged;
                }
                else
                {
                    e.Owner = db.Users.FirstOrDefault(x => x.Id == e.Owner.Id);
                    db.Events.Add(e);
                }

                db.SaveChanges();
            }
            return new SaveResult<Event>(true, e);
        }
Пример #8
0
        private double GetEventStorageSize(Event e)
        {
            //For each MediaPost
            var storageUsed = e.Posts.Where<Post>(p => p.BlobId != null)
                                    .Select<Post, double>(p =>
            {
                //Gets the storage used for that blob from FooCDN
                var blobId = ((Post)p).BlobId;
                var fooResult = ServiceManager.Kernel.Get<IFooCDNManager>().GetInfo(blobId);

                if (fooResult.StatusCode == HttpStatusCode.OK)
                {
                    var dictionary = fooResult.Value as Dictionary<string, dynamic>;
                    return Double.Parse(dictionary["BlobSize"]) / 1e6;
                }
                else
                {
                    return 0;
                }
            }).Sum();

            return storageUsed;
        }
Пример #9
0
 private double EstimateViewCount(Event e)
 {
     /*
      * Past events will be viewed 0.5 times per user
      * Events today will be viewed twice per hour per user
      */
     if (e.EndTime < DateTime.Now)
     {
         return 0.5 * e.Guests.Count;
     }
     else if (e.StartTime > DateTime.Now && e.StartTime < DateTime.Now.AddDays(1))
     {
         return 2 * ((e.EndTime - e.StartTime).Hours + 1) * e.Guests.Count;
     }
     else
     {
         return 0;
     }
 }