public IHttpActionResult GetApp(Guid appId) { try { using (MususAppEntities entity = new MususAppEntities()) { var appMaster = entity.AppMasters.FirstOrDefault(x => x.Id == appId); AppMasterDto app = new AppMasterDto(); var rating = entity.Ratings.Where(x => x.AppId == appMaster.Id); if (rating != null && rating.Count() > 0) { app.Rating = rating.Average(x => x.Point); } else { app.Rating = 0; } var useRating = entity.Ratings.FirstOrDefault(x => x.AppId == appMaster.Id && x.Username.Contains(RequestContext.Principal.Identity.Name)); if (useRating != null) { app.UserRating = useRating.Point; } GetPostComment(entity, appMaster, app, RequestContext.Principal.Identity.Name.ToString()); MapHostedAppObject(appMaster, app); return(Ok(app)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult PutDownloadCountMaster(Guid appId) { try { using (MususAppEntities entity = new MususAppEntities()) { var appMaster = entity.AppMasters.FirstOrDefault(x => x.Id == appId); if (appMaster != null) { if (appMaster.Download == null) { appMaster.Download = 1; } else { appMaster.Download += 1; } } entity.SaveChanges(); return(Ok(appMaster)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult GetDocument(string appId) { try { using (MususAppEntities entity = new MususAppEntities()) { var appMaster = entity.DocumentMasters.FirstOrDefault(x => x.Id.ToString() == appId); var rating = entity.Ratings.Where(x => x.AppId == appMaster.Id); DocumentMasterDto app = new DocumentMasterDto(); if (rating != null && rating.Count() > 0) { app.Rating = rating.Average(x => x.Point); } else { app.Rating = 0; } MapDocuments(appMaster, app); return(Ok(app)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult PostComment(Guid appId, CommentReview review) { try { using (MususAppEntities entity = new MususAppEntities()) { if (review != null) { if (review.Id > 0) { var post = entity.Posts.FirstOrDefault(x => x.Id == review.Id); post.Txt = review.Comment; post.CreateTime = DateTime.UtcNow; if (post != null && review.Review != null) { entity.SaveChanges(); var comment = entity.Comments.FirstOrDefault(x => x.PostId == post.Id); comment.Msg = review.Review; comment.UserName = review.ReviewUsername; comment.CreateTime = DateTime.UtcNow; } } else { var post = entity.Posts.Add(new Post() { AppId = appId, CreateTime = DateTime.UtcNow, Txt = review.Comment, UserName = review.Username }); entity.SaveChanges(); if (post != null) { entity.Comments.Add(new Comment() { CreateTime = DateTime.UtcNow, PostId = post.Id, Msg = review.Review, UserName = null }); } } } entity.SaveChanges(); return(Ok()); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult GetCategories() { try { using (MususAppEntities entity = new MususAppEntities()) { var app = entity.Categories.ToList(); return(Ok(app)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult PostCategory(Category category) { try { using (MususAppEntities entity = new MususAppEntities()) { entity.Categories.Add(category); entity.SaveChanges(); return(Ok(category)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult DeleteThirdPartyApp(Guid id) { try { using (MususAppEntities entity = new MususAppEntities()) { var app = entity.ThirdParties.FirstOrDefault(x => x.Id == id); app.IsDeleted = true; app.DeletedTime = DateTime.Now; entity.SaveChanges(); return(Ok("third party app changed successfully")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult DeleteAppMaster(AppMaster master) { try { using (MususAppEntities entity = new MususAppEntities()) { var app = entity.AppMasters.FirstOrDefault(x => x.Id == master.Id); app.IsDeleted = true; app.DeletedTime = DateTime.Now; entity.SaveChanges(); return(Ok("hosted app updated successfully")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult DeleteDocuments(Guid id) { try { using (MususAppEntities entity = new MususAppEntities()) { var app = entity.DocumentMasters.FirstOrDefault(x => x.Id == id); app.IsDeleted = true; app.DeletedTime = DateTime.Now; entity.SaveChanges(); return(Ok("web page app deleted successfully")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult PostDocuments() { try { using (MususAppEntities entity = new MususAppEntities()) { var httpRequest = HttpContext.Current.Request; DocumentMaster master = null; if (httpRequest.Params["id"] != null) { var id = Guid.Parse(httpRequest.Params["id"]); master = entity.DocumentMasters.FirstOrDefault( x => x.Id == id); if (master != null) { UploadAttachments(master); } else { BadRequest("Document not found"); } } else { master = new DocumentMaster(); master.Id = Guid.NewGuid(); master.DeletedTime = null; master.IsDeleted = false; master.CreatedTime = DateTime.UtcNow; UploadAttachments(master); entity.DocumentMasters.Add(master); } entity.SaveChanges(); return(Ok(master)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult PutDocuments(DocumentMaster master) { try { using (MususAppEntities entity = new MususAppEntities()) { var app = entity.DocumentMasters.FirstOrDefault(x => x.Id == master.Id); app.Description = master.Description; app.Documents = master.Documents; app.Title = master.Title; entity.SaveChanges(); return(Ok("web page app changed successfully")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Put(int rating, Guid appId) { try { using (MususAppEntities entity = new MususAppEntities()) { entity.Ratings.Add(new Rating() { AppId = appId, Point = rating, Username = RequestContext.Principal.Identity.Name }); entity.SaveChanges(); return(Ok()); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult PostThirdPartyApp() { try { using (MususAppEntities entity = new MususAppEntities()) { var httpRequest = HttpContext.Current.Request; ThirdParty master = null; if (httpRequest.Params["id"] != null) { var id = Guid.Parse(httpRequest.Params["id"]); master = entity.ThirdParties.FirstOrDefault(x => x.Id == id); if (master != null) { UploadAttachments(master); } else { return(BadRequest("Thirdparty app does not exists")); } } else { master = new ThirdParty(); master.CreatedTime = DateTime.UtcNow; master.IsDeleted = false; master.DeletedTime = null; master.Id = Guid.NewGuid(); UploadAttachments(master); entity.ThirdParties.Add(master); } entity.SaveChanges(); return(Ok(master)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult Login(LoginRequest loginRequest) { try { if (loginRequest.Username == null || loginRequest.Password == null) { return(BadRequest("Username/Password is mandatory")); } using (MususAppEntities entity = new MususAppEntities()) { var user = entity.UserInfoes.FirstOrDefault( x => x.UserName == loginRequest.Username && x.Password == loginRequest.Password && x.IsActive == true); if (user != null) { string token = CreateToken(user.UserName); return(Ok(new UserDetails() { Firstname = user.FirstName, Lastname = user.LastName, IsActive = user.IsActive, Username = user.UserName, TokenValidity = DateTime.UtcNow.AddDays(Convert.ToInt16(ConfigurationManager.AppSettings["jwtValidity"])), Token = token, IsAdmin = user.IsAdmin })); } else { return(BadRequest("invalid username/password")); } } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult GetWebPages(int page = 1, int size = 10) { try { using (MususAppEntities entity = new MususAppEntities()) { List <WebPageUrl> apps = entity.WebPageUrls.OrderBy(x => x.Documents).Skip(page - 1).Take(10).ToList(); List <WebpageUrlDto> dtos = new List <WebpageUrlDto>(); foreach (var app in apps) { WebpageUrlDto dto = new WebpageUrlDto(); MapWebpageApp(app, dto); dtos.Add(dto); } return(Ok(dtos)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult GetThirdPartyApps(int page = 1, int size = 10) { try { using (MususAppEntities entity = new MususAppEntities()) { List <ThirdParty> appmasters = entity.ThirdParties.OrderBy(x => x.Documents).Skip(page - 1).Take(10).ToList(); List <ThirdPartyDto> apps = new List <ThirdPartyDto>(); foreach (var app in appmasters) { ThirdPartyDto dto = new ThirdPartyDto(); MapThirdPartyApp(app, dto); apps.Add(dto); } return(Ok(apps)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult GetAllApps(int page = 1, int size = 10) { try { using (MususAppEntities entity = new MususAppEntities()) { List <AppMaster> appmasters = entity.AppMasters.OrderBy(x => x.Documents).Skip(page - 1).Take(10).ToList(); List <AppMasterDto> apps = new List <AppMasterDto>(); foreach (var master in appmasters) { AppMasterDto dto = new AppMasterDto(); MapHostedAppObject(master, dto); apps.Add(dto); } return(Ok(apps)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult GetDocuments(int page = 1, int size = 10) { try { using (MususAppEntities entity = new MususAppEntities()) { List <DocumentMaster> masters = entity.DocumentMasters.OrderBy(x => x.Documents).Skip(page - 1).Take(10).ToList(); List <DocumentMasterDto> dtos = new List <DocumentMasterDto>(); foreach (var master in masters) { DocumentMasterDto dto = new DocumentMasterDto(); MapDocuments(master, dto); dtos.Add(dto); } return(Ok(dtos)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IHttpActionResult DeleteCategory(int id) { try { using (MususAppEntities entity = new MususAppEntities()) { var cat = entity.Categories.FirstOrDefault(x => x.Id == id); if (cat == null) { return(BadRequest()); } else { entity.Categories.Remove(cat); entity.SaveChanges(); return(Ok()); } } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private static void GetPostComment(MususAppEntities entity, AppMaster appMaster, AppMasterDto app, string userName) { var userPost = entity.Posts.FirstOrDefault(x => x.AppId == appMaster.Id && x.UserName == userName); if (userPost != null) { var userCR = new CommentReview() { Comment = userPost.Txt, CommentDate = userPost.CreateTime, Username = userName, Id = userPost.Id }; var userComment = entity.Comments.FirstOrDefault(x => x.PostId == userPost.Id); if (userComment != null) { userCR.Review = userComment.Msg; userCR.ReviewDate = userComment.CreateTime; userCR.ReviewUsername = userComment.UserName; } app.UserComment = userCR; } if (app.UserComment == null) { var posts = entity.Posts.Where(x => x.AppId == appMaster.Id).OrderByDescending(x => x.CreateTime); if (posts != null) { foreach (var post in posts) { var review = entity.Comments.FirstOrDefault(x => x.PostId == post.Id); if (review != null) { app.CommentReviews.Add(new CommentReview() { Id = post.Id, Comment = post.Txt, CommentDate = post.CreateTime, Review = review.Msg, ReviewDate = review.CreateTime, ReviewUsername = review.UserName, Username = post.UserName }); } else { app.CommentReviews.Add(new CommentReview() { Id = post.Id, Comment = post.Txt, CommentDate = post.CreateTime }); } } } } else { var posts = entity.Posts.Where(x => x.AppId == appMaster.Id).OrderByDescending(x => x.CreateTime); if (posts != null) { foreach (var post in posts) { var review = entity.Comments.FirstOrDefault(x => x.PostId == post.Id); if (review != null) { app.CommentReviews.Add(new CommentReview() { Id = post.Id, Comment = post.Txt, CommentDate = post.CreateTime, Review = review.Msg, ReviewDate = review.CreateTime, ReviewUsername = review.UserName, Username = post.UserName }); } else { app.CommentReviews.Add(new CommentReview() { Id = post.Id, Comment = post.Txt, CommentDate = post.CreateTime }); } } } } }