Пример #1
0
 public object Any(ClientTechnology request)
 {
     return(!ShowServerHtml()
         ? AngularJsApp()
         : new HttpResult(base.Gateway.Send(new GetTechnology {
         Slug = request.Slug
     }))
     {
         View = "Tech"
     });
 }
Пример #2
0
 public object Any(ClientTechnology request)
 {
     return(!ShowServerHtml()
         ? AngularJsApp()
         : new HttpResult(base.ExecuteRequest(new GetTechnology {
         Reload = true, Slug = request.Slug
     }))
     {
         View = "Tech"
     });
 }
Пример #3
0
        public object Post(CreateTechnology request)
        {
            var slug         = request.Name.GenerateSlug();
            var existingTech = Db.Single <Technology>(q => q.Name == request.Name || q.Slug == slug);

            if (existingTech != null)
            {
                throw new ArgumentException("'{0}' already exists".Fmt(slug));
            }

            var tech    = request.ConvertTo <Technology>();
            var session = SessionAs <AuthUserSession>();

            tech.CreatedBy      = session.UserName;
            tech.Created        = DateTime.UtcNow;
            tech.LastModifiedBy = session.UserName;
            tech.LastModified   = DateTime.UtcNow;
            tech.OwnerId        = session.UserAuthId;
            tech.LogoApproved   = true;
            tech.Slug           = slug;

            var id = Db.Insert(tech, selectIdentity: true);
            var createdTechStack = Db.SingleById <Technology>(id);

            var history = createdTechStack.ConvertTo <TechnologyHistory>();

            history.TechnologyId = id;
            history.Operation    = "INSERT";
            Db.Insert(history);

            ContentCache.ClearAll();

            var postUpdate = AppSettings.EnableTwitterUpdates();

            if (postUpdate)
            {
                var url = new ClientTechnology {
                    Slug = tech.Slug
                }.ToAbsoluteUri();
                PostTwitterUpdate(
                    "Who's using #{0}? {1}".Fmt(tech.Slug.Replace("-", ""), url),
                    Db.ColumnDistinct <long>(Db.From <TechnologyChoice>()
                                             .Where(x => x.TechnologyId == tech.Id)
                                             .Select(x => x.TechnologyStackId)).ToList(),
                    maxLength: 140 - (TweetUrlLength - url.Length));
            }

            return(new CreateTechnologyResponse
            {
                Result = createdTechStack,
            });
        }
Пример #4
0
        public object Put(UpdateTechnology request)
        {
            var tech = Db.SingleById <Technology>(request.Id);

            if (tech == null)
            {
                throw HttpError.NotFound("Tech not found");
            }

            var session = SessionAs <AuthUserSession>();

            if (tech.IsLocked && !(tech.OwnerId == session.UserAuthId || session.HasRole(RoleNames.Admin)))
            {
                throw HttpError.Unauthorized("This Technology is locked and can only be modified by its Owner or Admins.");
            }

            //Only Post an Update if there was no other update today
            var postUpdate = AppSettings.EnableTwitterUpdates() &&
                             tech.LastStatusUpdate.GetValueOrDefault(DateTime.MinValue) < DateTime.UtcNow.Date;

            tech.PopulateWith(request);
            tech.LastModifiedBy = session.UserName;
            tech.LastModified   = DateTime.UtcNow;

            if (postUpdate)
            {
                tech.LastStatusUpdate = tech.LastModified;
            }

            Db.Save(tech);

            var history = tech.ConvertTo <TechnologyHistory>();

            history.TechnologyId = tech.Id;
            history.Operation    = "UPDATE";
            Db.Insert(history);

            ContentCache.ClearAll();

            var response = new UpdateTechnologyResponse
            {
                Result = tech
            };

            if (postUpdate)
            {
                var url = new ClientTechnology {
                    Slug = tech.Slug
                }.ToAbsoluteUri();
                response.ResponseStatus = new ResponseStatus
                {
                    Message = PostTwitterUpdate(
                        "Who's using #{0}? {1}".Fmt(tech.Slug.Replace("-", ""), url),
                        Db.ColumnDistinct <long>(Db.From <TechnologyChoice>()
                                                 .Where(x => x.TechnologyId == tech.Id)
                                                 .Select(x => x.TechnologyStackId)).ToList(),
                        maxLength: 140 - (TweetUrlLength - url.Length))
                };
            }

            return(response);
        }