public HttpResponseMessage Upload() { HttpResponseMessage response; try { long saplingid = 0; var httpRequest = HttpContext.Current.Request; if (httpRequest.Files.Count > 0) { byte[] fileData = null; using (var binaryReader = new BinaryReader(httpRequest.Files[0].InputStream)) { fileData = binaryReader.ReadBytes(httpRequest.Files[0].ContentLength); } Guid loggedUserId = default(Guid); if (loggedUserId == default(Guid)) { Guid.TryParse("5F246DDC-B744-46BC-8C90-E431A9264326", out loggedUserId); } saplingid = SaplingFacade.UploadImage(loggedUserId, fileData); } response = Request.CreateResponse(HttpStatusCode.OK, saplingid); } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); } return(response); }
public HttpResponseMessage GetSaplingById(long Id) { HttpResponseMessage response; try { Guid loggedUserId = User.Identity.IsAuthenticated ? Guid.Parse(User.Identity.GetUserId()) : default(Guid); var result = SaplingFacade.GetSapling(Id, loggedUserId); response = Request.CreateResponse(HttpStatusCode.OK, result); } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); } return(response); }
public IHttpActionResult Login(LoginBindingModel loginModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // var loggedUser = new ApplicationUser() { UserName = loginModel.UserName, Email = "" }; var loggedUser = UserManager.Find(loginModel.UserName, loginModel.Password); User _user = SaplingFacade.GetUser(loggedUser.Id); if (loggedUser == null) { return(Unauthorized()); } var accessToken = GenerateLocalAccessTokenResponse(loggedUser, _user, false); return(Ok(accessToken)); }
public HttpResponseMessage SaveSapling(SaplingsSaveDetails saplingsSaveDetails) { HttpResponseMessage response; try { Guid loggedUserId = User.Identity.IsAuthenticated ? Guid.Parse(User.Identity.GetUserId()) : default(Guid); if (loggedUserId == default(Guid)) { Guid.TryParse("5F246DDC-B744-46BC-8C90-E431A9264326", out loggedUserId); } var result = SaplingFacade.SaveSapling(saplingsSaveDetails, loggedUserId); response = Request.CreateResponse(HttpStatusCode.OK, result); } catch (Exception ex) { response = Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); } return(response); }