// GET api/values public IEnumerable <CouponViewModel> Get() { IList <CouponViewModel> listCouponViewModel = new List <CouponViewModel>(); using (PatuhEntities db = new PatuhEntities()) { IList <MsCoupon> couponList = db.MsCoupons.OrderBy(x => x.Id).ToList(); if (couponList != null && couponList.Count > 0) { foreach (MsCoupon coupon in couponList) { CouponViewModel row = new CouponViewModel(); row.Id = coupon.Id; row.Title = coupon.Title; row.Benefit = coupon.Benefit; row.Usage = coupon.Usage; row.Tnc = coupon.Tnc; row.PointNeeded = coupon.PointNeeded ?? 0; row.ValidUntil = coupon.ValidUntil; //row.CouponImage = coupon.CouponImage; row.cStatus = coupon.cStatus; row.cCreated = coupon.cCreated; row.dCreated = coupon.dCreated; row.cLastUpdated = coupon.cLastUpdated; row.dLastUpdated = coupon.dLastUpdated; listCouponViewModel.Add(row); } } return(listCouponViewModel); } }
public IList <ArticleViewModel> Get(string UserID) { IList <ArticleViewModel> articleViewModels = new List <ArticleViewModel>(); using (PatuhEntities db = new PatuhEntities()) { IList <TrArticle> articles = db.TrArticles.Where(x => x.cCreated == UserID && x.Category == "NEWS").ToList(); foreach (TrArticle article in articles) { ArticleViewModel articleViewModel = new ArticleViewModel(); articleViewModel.Id = article.Id; articleViewModel.Title = article.Title; articleViewModel.Category = article.Category; articleViewModel.Story = article.Story; articleViewModel.GPSLocation = article.GPSLocation; articleViewModel.GPSLong = article.GPSLong; articleViewModel.GPSLat = article.GPSLat; articleViewModel.ImageIds = db.TrImageAttachments.Where(x => x.HeaderId == article.Id).Select(y => y.Id).ToArray(); articleViewModel.cCreated = article.cCreated; articleViewModel.dCreated = article.dCreated; articleViewModel.cLastUpdated = article.cLastUpdated; articleViewModel.dLastUpdated = article.dLastUpdated; articleViewModels.Add(articleViewModel); } } return(articleViewModels); }
public HttpResponseMessage GetProfilePic(string UserID) { using (PatuhEntities db = new PatuhEntities()) { MsMobileUserProfile profile = db.MsMobileUserProfiles.Where(x => x.UserID == UserID).FirstOrDefault(); try { //Stream stream = new MemoryStream(profile.ProfilePic); //FileStream fileStream = File.OpenRead(profile.ProfilePicPath); //long fileLength = new FileInfo(profile.ProfilePicPath).Length; var response = new HttpResponseMessage(); //response.Content = new StreamContent(fileStream); response.Content = new ByteArrayContent(profile.ProfilePic); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline"); response.Content.Headers.ContentDisposition.FileName = "image"; response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); response.Content.Headers.ContentLength = profile.ProfilePic.Length;//fileLength; return(response); } catch (Exception e) { Console.WriteLine(e); throw; } } }
public HttpResponseMessage GetCouponImage(long msCouponId) { using (PatuhEntities db = new PatuhEntities()) { MsCoupon image = db.MsCoupons.Where(x => x.Id == msCouponId).FirstOrDefault(); try { var response = new HttpResponseMessage(); //response.Content = new StreamContent(fileStream); response.Content = new ByteArrayContent(image.CouponImage); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("inline"); response.Content.Headers.ContentDisposition.FileName = "image"; response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpg"); response.Content.Headers.ContentLength = image.CouponImage.Length;//fileLength; return(response); } catch (Exception e) { Console.WriteLine(e); throw; } } }
// 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); }
// GET api/values/5 public object Get(string UserID, string password) { using (PatuhEntities db = new PatuhEntities()) { MsMobileUserProfile profile = db.MsMobileUserProfiles.Where(x => x.UserID == UserID).First(); return(profile); } }
// GET api/values/5 public object Get(long ArticleId) { using (PatuhEntities db = new PatuhEntities()) { IList <TrLike> likeList = db.TrLikes.Where(x => x.ArticleId == ArticleId).ToList(); return(likeList); } }
// GET api/values/5 public object Get(long ArticleId) { using (PatuhEntities db = new PatuhEntities()) { IList <TrComment> commentList = db.TrComments.Where(x => x.ArticleId == ArticleId).ToList(); return(commentList); } }
public object Get(long ArticleId, string UserID) { using (PatuhEntities db = new PatuhEntities()) { IList <TrLike> likeList = db.TrLikes.Where(x => x.ArticleId == ArticleId && x.cCreated == UserID).ToList(); return(likeList); } }
// 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); }
// GET api/values public object Get() { try { using (PatuhEntities db = new PatuhEntities()) { var obj = db.MsMobileUserProfiles.ToList(); return(obj); } } catch (Exception e) { return(e); } }
public object Get(string UserID) { Int64 pointsEarned = 0; using (PatuhEntities db = new PatuhEntities()) { IList <TrPoint> listPoint = db.TrPoints.Where(x => x.UserID == UserID).ToList(); if (listPoint != null) { pointsEarned = (listPoint.Select(x => x.PointValue.Value).Sum()); } //Int64 pointsEarned = db.TrPoints.Where(x => x.UserID == UserID).DefaultIfEmpty(new TrPoint()).Select(x => x.PointValue.Value).Sum(); return(new { point = pointsEarned }); } }
// GET api/values/5 public object Get(string UserID) { IList <UserCouponViewModel> listUserCouponViewModel = new List <UserCouponViewModel>(); using (PatuhEntities db = new PatuhEntities()) { IList <TrUserCoupon> userCouponList = db.TrUserCoupons.Where(x => x.UserID == UserID).OrderBy(x => x.Id).ToList(); if (userCouponList != null && userCouponList.Count > 0) { foreach (TrUserCoupon userCoupon in userCouponList) { MsCoupon coupon = db.MsCoupons.Where(y => y.Id == userCoupon.MsCouponId).FirstOrDefault(); UserCouponViewModel row = new UserCouponViewModel(); row.Id = userCoupon.Id; row.UserID = userCoupon.UserID; row.MsCouponId = userCoupon.MsCouponId ?? 0; row.CouponCode = userCoupon.CouponCode; row.Title = coupon.Title; row.Benefit = coupon.Benefit; row.Usage = coupon.Usage; row.Tnc = coupon.Tnc; row.PointNeeded = coupon.PointNeeded ?? 0; row.ValidUntil = coupon.ValidUntil; //row.CouponImage = coupon.CouponImage; row.cStatus = coupon.cStatus; row.cCreated = coupon.cCreated; row.dCreated = coupon.dCreated; row.cLastUpdated = coupon.cLastUpdated; row.dLastUpdated = coupon.dLastUpdated; listUserCouponViewModel.Add(row); } } return(listUserCouponViewModel); } }
// 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 = "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); }
// 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([FromBody] LoginCredentialViewModel loginCredential) { //string hashedPassword = Security.HashSHA1(loginCredential.password + userGuid.ToString()); LoginStatusViewModel loginStatus = new LoginStatusViewModel(); loginStatus.userId = ""; loginStatus.userName = ""; loginStatus.userAccountType = ""; MsMobileUserProfile matchUser; try { using (PatuhEntities db = new PatuhEntities()) { //MsMobileUserProfile listProfile = db.MsMobileUserProfiles.Where(x => x.UserID == loginCredential.userId).FirstOrDefault(); matchUser = db.MsMobileUserProfiles.Where(x => x.UserID == loginCredential.userId).FirstOrDefault();//db.MsMobileUserProfiles.Where(x => x.UserID == loginCredential.userId).DefaultIfEmpty(new MsMobileUserProfile()).FirstOrDefault(); if (matchUser != null) { string hashedPassword = Security.HashSHA1(loginCredential.password + matchUser.UserGuid); if (matchUser.Pwd == hashedPassword) { // The password is correct loginStatus.userId = matchUser.UserID ?? ""; loginStatus.userName = matchUser.FullName ?? ""; loginStatus.userAccountType = matchUser.UserAccountType ?? ""; MsMobileUserProfileViewModel msMobileUserProfileViewModel = new MsMobileUserProfileViewModel(); msMobileUserProfileViewModel.UserID = matchUser.UserID; msMobileUserProfileViewModel.Pwd = matchUser.Pwd; msMobileUserProfileViewModel.UserGuid = matchUser.UserGuid; msMobileUserProfileViewModel.UserAccountType = matchUser.UserAccountType; msMobileUserProfileViewModel.FullName = matchUser.FullName; msMobileUserProfileViewModel.DOB = (matchUser.DOB != null ? matchUser.DOB.Value.ToString("dd-MM-yyyy") : ""); msMobileUserProfileViewModel.Location = matchUser.Location; msMobileUserProfileViewModel.PhoneNo = matchUser.PhoneNo; msMobileUserProfileViewModel.Email = matchUser.Email; IList <TrPoint> listPoint = db.TrPoints.Where(x => x.UserID == matchUser.UserID).ToList(); if (listPoint != null) { msMobileUserProfileViewModel.PointReward = (listPoint.Select(x => x.PointValue.Value).Sum()); } loginStatus.userProfile = msMobileUserProfileViewModel; } } } } catch (Exception e) { return(e); } return(loginStatus); }