// POST api/values public object Post() { JsonResultViewModel result = new JsonResultViewModel(); result.status = true; result.message = "Coupon successfully claimed"; result.messageCode = "S"; var httpRequest = HttpContext.Current.Request; long id = string.IsNullOrEmpty(httpRequest["msCouponId"]) ? 0 : long.Parse(httpRequest["msCouponId"]); string userId = httpRequest["UserId"]; try { using (PatuhEntities db = new PatuhEntities()) { MsCoupon msCoupon = db.MsCoupons.Where(x => x.Id == id).FirstOrDefault(); TrUserCoupon userCoupon = db.TrUserCoupons.Where(x => x.MsCouponId == id).FirstOrDefault(); if (userCoupon == null) { userCoupon = new TrUserCoupon(); userCoupon.MsCouponId = id; userCoupon.UserID = userId; userCoupon.cCreated = userId; userCoupon.dCreated = DateTime.Now; db.TrUserCoupons.AddObject(userCoupon); } userCoupon.cStatus = "Y"; /* * if (httpRequest.Files.Count > 0) * { * * foreach (string file in httpRequest.Files) * { * var postedFile = httpRequest.Files[file]; * Type fileType = postedFile.GetType(); * byte[] couponImage = new byte[postedFile.ContentLength]; * * postedFile.InputStream.Read(couponImage, 0, postedFile.ContentLength); * userCoupon.c * } */ db.SaveChanges(); } } catch (Exception e) { result.status = false; result.message = e.Message; result.messageCode = "Error in claiming Coupon"; } return(result); }
// POST api/values public object Post([FromBody] ArticleReportViewModel trArticleReport) { JsonResultViewModel result = new JsonResultViewModel(); result.status = true; result.message = "Article successfully reported"; result.messageCode = "S"; var httpRequest = HttpContext.Current.Request; try { using (PatuhEntities db = new PatuhEntities()) { IList <TrArticleReport> articleReports = db.TrArticleReports.Where(x => x.ArticleId == trArticleReport.ArticleId && x.cCreated == trArticleReport.cCreated).ToList(); TrArticleReport articleReport; if (articleReports == null || articleReports.Count == 0) { articleReport = new TrArticleReport(); articleReport.ArticleId = trArticleReport.ArticleId; articleReport.ReportCategory = trArticleReport.ReportCategory; articleReport.ReportDesc = trArticleReport.ReportDesc; articleReport.cStatus = trArticleReport.cStatus; articleReport.cCreated = trArticleReport.cCreated; articleReport.dCreated = DateTime.Now; db.TrArticleReports.AddObject(articleReport); } else { articleReport = articleReports.FirstOrDefault(); } articleReport.cLastUpdated = trArticleReport.cLastUpdated; articleReport.dLastUpdated = DateTime.Now; db.SaveChanges(); } } catch (Exception e) { result.status = false; result.message = e.Message; result.messageCode = "Error in reporting Article"; } return(result); }
// POST api/values public object Post() { JsonResultViewModel result = new JsonResultViewModel(); result.status = true; result.message = "Coupon successfully claimed"; result.messageCode = "S"; var httpRequest = HttpContext.Current.Request; long id = string.IsNullOrEmpty(httpRequest["msCouponId"]) ? 0 : long.Parse(httpRequest["msCouponId"]); string userId = httpRequest["UserId"]; try { using (PatuhEntities db = new PatuhEntities()) { MsCoupon msCoupon = db.MsCoupons.Where(x => x.Id == id).FirstOrDefault(); long totalPoint = db.TrPoints.Where(x => x.UserID == userId).Sum(x => x.PointValue) ?? 0; if ((totalPoint - msCoupon.PointNeeded) < 0) { result.status = false; result.message = "User Points is not enough to claim the coupon"; result.messageCode = "Error in claiming Coupon"; return(result); } TrUserCoupon userCoupon = db.TrUserCoupons.Where(x => x.MsCouponId == id).FirstOrDefault(); if (userCoupon == null) { CouponCode.CouponCodeBuilder couponBuilder = new CouponCode.CouponCodeBuilder(); CouponCode.Options opt = new CouponCode.Options(); string couponCode = couponBuilder.Generate(opt); userCoupon = new TrUserCoupon(); userCoupon.MsCouponId = id; userCoupon.UserID = userId; userCoupon.CouponCode = couponCode; userCoupon.cCreated = userId; userCoupon.dCreated = DateTime.Now; db.TrUserCoupons.AddObject(userCoupon); TrPoint trPoint = new TrPoint(); trPoint.ArticleId = 0; trPoint.UserID = userId; trPoint.ActionCode = "CLAIM"; trPoint.PointValue = (msCoupon.PointNeeded * -1); trPoint.cCreated = userId; trPoint.dCreated = DateTime.Now; trPoint.cLastUpdated = userId; trPoint.dLastUpdated = DateTime.Now; db.TrPoints.AddObject(trPoint); } userCoupon.cStatus = "Y"; /* * if (httpRequest.Files.Count > 0) * { * * foreach (string file in httpRequest.Files) * { * var postedFile = httpRequest.Files[file]; * Type fileType = postedFile.GetType(); * byte[] couponImage = new byte[postedFile.ContentLength]; * * postedFile.InputStream.Read(couponImage, 0, postedFile.ContentLength); * userCoupon.c * } */ db.SaveChanges(); } } catch (Exception e) { result.status = false; result.message = e.Message; result.messageCode = "Error in claiming Coupon"; } return(result); }
// POST api/values public object Post() { JsonResultViewModel result = new JsonResultViewModel(); result.status = true; result.message = "News successfully updated"; result.messageCode = "S"; var httpRequest = HttpContext.Current.Request; long id = string.IsNullOrEmpty(httpRequest["Id"]) ? 0 : long.Parse(httpRequest["Id"]); string title = httpRequest["title"]; string story = httpRequest["story"]; string location = httpRequest["location"]; double latitude = string.IsNullOrEmpty(httpRequest["latitude"]) ? 0 : double.Parse(httpRequest["latitude"]); double longitude = string.IsNullOrEmpty(httpRequest["longitude"]) ? 0 : double.Parse(httpRequest["longitude"]); string userId = httpRequest["userId"]; try { using (PatuhEntities db = new PatuhEntities()) { TrArticle article = db.TrArticles.Where(x => x.Id == id).FirstOrDefault(); if (article == null) { article = new TrArticle(); article.cCreated = userId; article.dCreated = DateTime.Now; db.TrArticles.AddObject(article); } article.Category = "ARTICLE"; article.Title = title; article.Story = story; article.GPSLocation = location; article.GPSLong = longitude; article.GPSLat = latitude; article.cLastUpdated = userId; article.dLastUpdated = DateTime.Now; db.SaveChanges(); try { if (httpRequest.Files.Count > 0) { IList <TrImageAttachment> currentImages = db.TrImageAttachments.Where(x => x.HeaderId == article.Id).ToList(); if (currentImages != null && currentImages.Count > 0) { foreach (TrImageAttachment dbImg in currentImages) { db.TrImageAttachments.DeleteObject(dbImg); } } string extention = ""; string guid = ""; string[] supportedTypes = new string[] { "jpg", "jpeg", "bmp", "png" }; int fileSequence = 0; foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; Type fileType = postedFile.GetType(); if (postedFile != null) { if (postedFile.FileName != "") { byte[] theImage = new byte[postedFile.ContentLength]; extention = (Path.GetExtension(postedFile.FileName).TrimStart('.')).ToLower(); if (supportedTypes.Contains(extention)) { postedFile.InputStream.Read(theImage, 0, postedFile.ContentLength); TrImageAttachment imageAtt = new TrImageAttachment();// db.TrImageAttachments.Where(x => x.Id == id).FirstOrDefault(); imageAtt = new TrImageAttachment(); imageAtt.HeaderId = article.Id; imageAtt.cCreated = userId; imageAtt.dCreated = DateTime.Now; imageAtt.Sequence = ++fileSequence; imageAtt.Image = theImage; imageAtt.cLastUpdated = userId; imageAtt.dLastUpdated = DateTime.Now; db.TrImageAttachments.AddObject(imageAtt); db.SaveChanges(); } } } } } } catch (Exception e) { result.status = false; result.message = e.Message; result.messageCode = "Error in saving article"; return(result); } } } catch (Exception e) { result.status = false; result.message = e.Message; result.messageCode = "Error in saving Article"; } return(result); }
// POST api/values public object Post() { JsonResultViewModel result = new JsonResultViewModel(); result.status = true; result.message = "Comment successfully updated"; result.messageCode = "S"; var httpRequest = HttpContext.Current.Request; long id = string.IsNullOrEmpty(httpRequest["Id"]) ? 0 : long.Parse(httpRequest["Id"]); long articleId = string.IsNullOrEmpty(httpRequest["ArticleId"]) ? 0 : long.Parse(httpRequest["ArticleId"]); string postedComment = httpRequest["Comment"]; string userId = httpRequest["userId"]; try { using (PatuhEntities db = new PatuhEntities()) { TrComment comment = db.TrComments.Where(x => x.Id == id).FirstOrDefault(); if (comment == null) { comment = new TrComment(); comment.cCreated = userId; comment.dCreated = DateTime.Now; db.TrComments.AddObject(comment); MsPoint msPoint = db.MsPoints.Where(x => x.ActionCode == "COMMENTART").FirstOrDefault(); if (msPoint != null) { TrArticle trArticle = db.TrArticles.Where(x => x.Id == articleId).FirstOrDefault(); if (trArticle != null) { TrPoint trPoint = new TrPoint(); trPoint.ArticleId = trArticle.Id; trPoint.UserID = trArticle.cCreated; trPoint.ActionCode = "COMMENTART"; trPoint.PointValue = msPoint.RewardPoint; trPoint.cCreated = userId; trPoint.dCreated = DateTime.Now; trPoint.cLastUpdated = userId; trPoint.dLastUpdated = DateTime.Now; db.TrPoints.AddObject(trPoint); //db.SaveChanges(); } } } comment.ArticleId = articleId; comment.Comment = postedComment; comment.cLastUpdated = userId; comment.dLastUpdated = DateTime.Now; db.SaveChanges(); } } catch (Exception e) { result.status = false; result.message = e.Message; result.messageCode = "Error in saving Comment"; } return(result); }
// POST api/values public object Post() { JsonResultViewModel result = new JsonResultViewModel(); result.status = true; result.message = "User Profile successfully updated"; result.messageCode = "S"; var httpRequest = HttpContext.Current.Request; string userId = httpRequest["userId"]; string password = httpRequest["password"]; string userName = httpRequest["userName"]; string email = httpRequest["email"]; string phoneNo = httpRequest["phoneNo"]; string location = httpRequest["location"]; string birthday = httpRequest["birthday"]; try { using (PatuhEntities db = new PatuhEntities()) { MsMobileUserProfile profile = db.MsMobileUserProfiles.Where(x => x.UserID == userId).FirstOrDefault(); byte[] profImage = null; Guid userGuid = System.Guid.NewGuid(); string hashedPassword = Security.HashSHA1(password + userGuid.ToString()); string profilePicPath = ""; try { if (httpRequest.Files.Count > 0) { string extention = ""; string guid = ""; string[] supportedTypes = new string[] { "jpg", "jpeg", "bmp", "png" }; foreach (string file in httpRequest.Files) { var postedFile = httpRequest.Files[file]; Type fileType = postedFile.GetType(); if (postedFile != null) { if (postedFile.FileName != "") { profImage = new byte[postedFile.ContentLength]; extention = (Path.GetExtension(postedFile.FileName).TrimStart('.')).ToLower(); if (supportedTypes.Contains(extention)) { guid = DateTime.Now.ToString("yyyyMMddhhmmss") + System.Guid.NewGuid().ToString("n") + Path.GetExtension(postedFile.FileName); //string filePath = Path.Combine(httpRequest.MapPath("~/PhotoUploads"), guid);// Path.GetFileName(postedFile.FileName)); postedFile.InputStream.Read(profImage, 0, postedFile.ContentLength); //postedFile.SaveAs(filePath); //FileInfo TheFile = new FileInfo(filePath); //if (TheFile.Exists) //{ // TheFile.MoveTo(Path.Combine(httpRequest.MapPath("~/PhotoUploads"), Path.GetFileName(guid))); //} //profilePicPath = TheFile.FullName; } } } } } } catch (Exception e) { result.status = false; result.message = e.Message; result.messageCode = "Error in saving User Profile child"; return(result); } if (profile == null) { profile = new MsMobileUserProfile(); db.MsMobileUserProfiles.AddObject(profile); } profile.UserID = userId; profile.FullName = userName; profile.Email = email; profile.PhoneNo = phoneNo; profile.Location = location; profile.DOB = string.IsNullOrEmpty(birthday) ? new DateTime() : DateTime.ParseExact(birthday, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture); profile.Pwd = hashedPassword; profile.UserGuid = userGuid; profile.ProfilePicPath = profilePicPath; profile.ProfilePic = profImage; profile.dCreated = DateTime.Now; profile.dLastUpdated = DateTime.Now; db.SaveChanges(); } } catch (Exception e) { result.status = false; result.message = e.Message; result.messageCode = "Error in saving User Profile"; } return(result); }