public Task <PostingViewModel> GetEmptyPosting(long categoryId) { var postingViewModel = new PostingViewModel(); postingViewModel.CategoryId = categoryId; postingViewModel.UserId = _currentUser.GetUserId <long>(); postingViewModel.Title = string.Empty; postingViewModel.Description = string.Empty; postingViewModel.CreationDate = DateTime.Now; postingViewModel.ExpirationDate = DateTime.Now; postingViewModel.Type = (int)EPostingTypes.Buy; postingViewModel.Id = string.Empty; var postingCategory = _netBazaarDatabase.Categories.Include("CategoryFields") .First(category => category.Id == postingViewModel.CategoryId); foreach (var categoryField in postingCategory.CategoryFields) { var postingFieldViewModel = new PostingFieldViewModel(); postingFieldViewModel.Type = categoryField.Type; postingFieldViewModel.BooleanValue = false; postingFieldViewModel.DecimalValue = 0; postingFieldViewModel.IntegerValue = 0; postingFieldViewModel.TextValue = string.Empty; postingFieldViewModel.CategoryFieldId = categoryField.Id; postingFieldViewModel.CategoryFieldName = categoryField .Name; postingViewModel.Fields.Add(postingFieldViewModel); } return(Task.FromResult(postingViewModel)); }
public ActionResult Posting() { var CustomerName = _context.Users.Where(x => x.Roles.Select(y => y.RoleId).Contains("1")).ToList(); PostingViewModel postingViewModel = new PostingViewModel() { ApplicationUser = CustomerName }; return(View(postingViewModel)); }
public ActionResult Ballot() { var viewModel = new PostingViewModel(); viewModel.President = dbContext.Presidents.Include(p => p.Qualification).ToList(); viewModel.VicePresident = dbContext.VicePresident.Include(p => p.Qualification).ToList(); viewModel.Secretary = dbContext.Secretary.Include(p => p.Qualification).ToList(); viewModel.Treasurer = dbContext.Treasurer.Include(p => p.Qualification).ToList(); viewModel.Members = dbContext.Members.Include(p => p.Qualification).ToList(); return(View(viewModel)); }
public Task <PostingViewModel> GetPosting(string postingId) { var query = Builders <BsonDocument> .Filter.Eq("id", ObjectId.Parse(postingId)); var postingsCollection = _netBazaarMongoDbDatabase.GetCollection <BsonDocument>("Postings"); var postingDocument = postingsCollection.Find(query).FirstOrDefault(); var postingViewModel = new PostingViewModel(); postingViewModel.CategoryId = postingDocument[nameof(postingViewModel.CategoryId)].AsInt64; postingViewModel.UserId = postingDocument[nameof(postingViewModel.UserId)].AsInt64; postingViewModel.Title = postingDocument[nameof(postingViewModel.Title)].AsString; postingViewModel.Description = postingDocument[nameof(postingViewModel.Description)].AsString; postingViewModel.CreationDate = postingDocument[nameof(postingViewModel.CreationDate)].ToLocalTime(); postingViewModel.ExpirationDate = postingDocument[nameof(postingViewModel.ExpirationDate)].ToLocalTime(); postingViewModel.Type = postingDocument[nameof(postingViewModel.Type)].AsInt32; postingViewModel.Id = postingDocument["_id"].AsObjectId.ToString(); var fieldDocuments = postingDocument["Fields"].AsBsonArray; var postingCategory = _netBazaarDatabase.Categories.Include("CategoryFields") .First(category => category.Id == postingViewModel.CategoryId); foreach (var fieldDocument in fieldDocuments) { var postingFieldViewModel = new PostingFieldViewModel(); var categoryField = postingCategory.CategoryFields.First(field => field.Id == postingFieldViewModel.CategoryFieldId); postingFieldViewModel.Type = categoryField.Type; postingFieldViewModel.BooleanValue = fieldDocument[nameof(postingFieldViewModel.BooleanValue)].AsNullableBoolean; postingFieldViewModel.DecimalValue = fieldDocument[nameof(postingFieldViewModel.DecimalValue)].AsNullableDouble; postingFieldViewModel.IntegerValue = fieldDocument[nameof(postingFieldViewModel.IntegerValue)].AsNullableInt32; postingFieldViewModel.TextValue = fieldDocument[nameof(postingFieldViewModel.TextValue)].AsString; postingFieldViewModel.CategoryFieldId = fieldDocument[nameof(postingFieldViewModel.CategoryFieldId)].AsInt32; postingFieldViewModel.CategoryFieldName = categoryField.Name; postingViewModel.Fields.Add(postingFieldViewModel); } return(Task.FromResult(postingViewModel)); }
private CategoryViewModel GetCategoryViewModel(long idSubarea) { CategoryViewModel cvm = new CategoryViewModel(); cvm.Category = dbContext.Category.SingleOrDefault(c => c.idSubarea == idSubarea); cvm.Topics = dbContext.Topic.Where(t => t.idCategory == cvm.Category.idCategory).ToList(); cvm.Postings = new List <PostingViewModel>(); string photo = "../images/blank-profile-picture.png"; ApplicationUser user = new ApplicationUser(); foreach (var topic in cvm.Topics) { user = dbContext.ApplicationUser.SingleOrDefault(u => u.Id == topic.idUser); if (user.UserPhoto != null) { var base64 = Convert.ToBase64String(user.UserPhoto); photo = String.Format("data:image/jpg;base64,{0}", base64); } ViewData["imgUserTopic"] = photo; List <Posting> postings = dbContext.Posting.Where(p => p.idTopic == topic.idTopic).ToList(); foreach (var post in postings) { photo = "../images/blank-profile-picture.png"; user = dbContext.ApplicationUser.SingleOrDefault(u => u.Id == post.idUser); if (user.UserPhoto != null) { var base64 = Convert.ToBase64String(user.UserPhoto); photo = String.Format("data:image/jpg;base64,{0}", base64); } PostingViewModel postingTarget = new PostingViewModel { idTopic = post.idTopic, idPosting = post.idPosting, idUser = post.idUser, Message = post.Message, imgSrc = photo }; cvm.Postings.Add(postingTarget); } } return(cvm); }
public ActionResult Posting([Bind(Include = "Title,CustomerId,Contents")] PostingViewModel postingViewModel) { var CutomerName = _context.Users.Where(x => x.Roles.Select(y => y.RoleId).Contains("1")).ToList(); postingViewModel.ApplicationUser = CutomerName; if (ModelState.IsValid) { PostingModel postingModel = new PostingModel() { Title = postingViewModel.Title, NutritionistId = User.Identity.GetUserId(), CustomerId = postingViewModel.CustomerId, PostTime = DateTime.Now, Content = postingViewModel.Contents }; _context.PostingModels.Add(postingModel); _context.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(postingViewModel)); }
public Task InsertPosting(PostingViewModel postingViewModel) { var posting = new BsonDocument(); posting.Add(new BsonElement(nameof(postingViewModel.CategoryId), postingViewModel.CategoryId)); posting.Add(new BsonElement(nameof(postingViewModel.UserId), postingViewModel.UserId)); posting.Add(new BsonElement(nameof(postingViewModel.Title), postingViewModel.Title)); posting.Add(new BsonElement(nameof(postingViewModel.Description), postingViewModel.Description)); posting.Add(new BsonElement(nameof(postingViewModel.CreationDate), postingViewModel.CreationDate)); posting.Add(new BsonElement(nameof(postingViewModel.ExpirationDate), postingViewModel.ExpirationDate)); posting.Add(new BsonElement(nameof(postingViewModel.Type), postingViewModel.Type)); var fields = new BsonArray(); foreach (var postingFieldViewModel in postingViewModel.Fields) { var field = new BsonDocument(); field.Add(nameof(postingFieldViewModel.BooleanValue), postingFieldViewModel.BooleanValue); field.Add(nameof(postingFieldViewModel.DecimalValue), postingFieldViewModel.DecimalValue); field.Add(nameof(postingFieldViewModel.IntegerValue), postingFieldViewModel.IntegerValue); field.Add(nameof(postingFieldViewModel.TextValue), postingFieldViewModel.TextValue); field.Add(new BsonElement(nameof(postingFieldViewModel.CategoryFieldId), postingFieldViewModel.CategoryFieldId)); fields.Add(field); } posting.Add("Fields", fields); var postingsCollection = _netBazaarMongoDbDatabase.GetCollection <BsonDocument>("Postings"); postingsCollection.InsertOne(posting); postingViewModel.Id = posting["_id"].AsObjectId.ToString(); return(Task.FromResult(0)); }
private async Task <TopicViewModel> GetTopicViewModel(long idTopic, int?page) { TopicViewModel tvm = new TopicViewModel(); tvm.topic = GetTopic(idTopic); var posting = from p in dbContext.Posting where p.idTopic == idTopic select p; tvm.postings = await PaginatedList <Posting> .CreateAsync(posting, page ?? 1, 10); tvm.postingsViewModel = new List <PostingViewModel>(); string photo = "../images/blank-profile-picture.png"; ApplicationUser user = new ApplicationUser(); user = dbContext.ApplicationUser.SingleOrDefault(u => u.Id == tvm.topic.idUser); if (user.UserPhoto != null) { var base64 = Convert.ToBase64String(user.UserPhoto); photo = String.Format("data:image/jpg;base64,{0}", base64); } ViewData["imgUserTopic"] = photo; foreach (var post in tvm.postings) { photo = "../images/blank-profile-picture.png"; user = dbContext.ApplicationUser.SingleOrDefault(u => u.Id == post.idUser); if (user.UserPhoto != null) { var base64 = Convert.ToBase64String(user.UserPhoto); photo = String.Format("data:image/jpg;base64,{0}", base64); } PostingViewModel postingTarget = new PostingViewModel { idTopic = post.idTopic, idPosting = post.idPosting, idUser = post.idUser, Message = post.Message, imgSrc = photo }; tvm.postingsViewModel.Add(postingTarget); } return(tvm); }
public Task UpdatePosting(PostingViewModel posting) { throw new NotImplementedException(); }