Esempio n. 1
0
        public IHttpActionResult GetClassified(string classifiedId)
        {
            ClaimsPrincipal principal = (ClaimsPrincipal)Request.GetRequestContext().Principal;
            var             userId    = principal.Identity.GetUserId();

            try
            {
                Classified classified = new Classified(Encoding.UTF8.GetString(Convert.FromBase64String(classifiedId)));
                classified.ValidOrBreak();

                classified.oCategory = new ClsGrpSimple(classified.Category);
                classified.CheckOwnership(userId);

                var newJsWidget = new UserJustShareWidget(classified);
                if (userId != null)
                {
                    newJsWidget.LoadMessages(userId);
                }

                return(Ok(
                           new
                {
                    justShareDetails = classified,
                    justShareWidget = newJsWidget
                }));
            }
            catch (InvalidModelException e)
            {
                return(BadRequest());
            }
            catch (Exception e)
            {
                return(BadRequest());
            }
        }
Esempio n. 2
0
        public IHttpActionResult AddMessage(SecureClassifiedMessage jsMsgForm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.WithoutFormName()));
            }

            /*
             * if (!Captcha.VerifyResponse(jsMsgForm.Captcha))
             * {
             *  ModelState.AddModelError("jsMsgForm.Captcha", "Captcha failed.");
             *  return BadRequest(ModelState.WithoutFormName());
             * }
             */

            try
            {
                ClaimsPrincipal principal  = (ClaimsPrincipal)Request.GetRequestContext().Principal;
                Classified      classified = new Classified(jsMsgForm.ClassifiedId);
                classified.ValidOrBreak();

                ClassifiedMessage message = new ClassifiedMessage()
                {
                    Id           = 0,
                    Message      = jsMsgForm.Message,
                    ClassifiedId = jsMsgForm.ClassifiedId,
                    From         = principal.Identity.GetUserId(),
                    To           = classified.CreatedBy
                };
                message.ValidOrBreak();
                message.Save();
                //return BadRequest("Error saving message. Try again later.");

                // Send message to JustShare creator if ConsentToContact
                classified.NotifyMessage(message);

                return(Ok());
            }
            catch (InvalidModelException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest("Error saving message. Try again later."));
            }
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> CreateClassified()
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            try
            {
                ClaimsPrincipal principal = (ClaimsPrincipal)Request.GetRequestContext().Principal;
                var             root      = HttpContext.Current.Server.MapPath("~/App_Data");

                var provider = new MultipartFormDataStreamProvider(root);
                await Request.Content.ReadAsMultipartAsync(provider);

                Directory.CreateDirectory(root);
                var classifiedForm = new ClassifiedForm(provider.FormData)
                {
                    CreatedBy = principal.Identity.GetUserId()
                };

                ModelState.Clear();
                this.Validate <ClassifiedForm>(classifiedForm);

                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState.WithoutFormName()));
                }

                var classified = new Classified(classifiedForm);
                classified.ValidOrBreak();
                classified.Save();

                var imageFile = ImageFactory.CreateFullImageModel("classifieds", classified.Id, provider.FileData);
                ImageContainer.UploadImage(imageFile);

                return(Ok());
            }
            catch (InvalidModelException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }