public ActionResult Create([Bind(Include = "Id,RecipientId,Name,Description,Amount,DateOfInitiative")] Collect collect) { if (ModelState.IsValid) { using (var collectService = new CollectsService()) { collect.OwnerId = GetUserId(); collectService.CollectAdd(collect); var newCollectionUsers = new CollectUser(); newCollectionUsers.UserId = collect.OwnerId; newCollectionUsers.CollectId = collect.Id; collectService.CollectUserAdd(newCollectionUsers); //Send Email using (var userService = new UsersService()) { collectService.SendEmailsCreate(userService.GetUserIndex().Where(i => i.Id != collect.RecipientId).ToList(), collect); } return(RedirectToAction("Details", "Collects", new { id = collect.Id })); } } using (var collectService = new CollectsService()) { ViewBag.OwnerId = new SelectList(collectService.AllMyUserList(), "Id", "Name", collect.OwnerId); ViewBag.RecipientId = new SelectList(collectService.AllMyUserList(), "Id", "Name", collect.RecipientId); return(View(collect)); } }
public void JoinConfirmed(int collectId, int userId) { if (!_unitOfWork.CollectUserRepository.Get().Any(i => i.CollectId == collectId && i.UserId == userId)) { CollectUser collectUser = new CollectUser(); collectUser.UserId = userId; collectUser.CollectId = collectId; collectUser.GaveMoney = false; _unitOfWork.CollectUserRepository.Add(collectUser); _unitOfWork.SaveChanges(); } }
protected override void Seed(ApplicationDbContext context) { string fName, sName, fEmail, Password, Role; DateTime bDate; //Tomasz Żurek fName = "Tomasz"; sName = "Żurek"; fEmail = "*****@*****.**"; Password = "******"; Role = "Admin"; bDate = DateTime.ParseExact("1997-05-20", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); var store = new UserStore <ApplicationUser>(context); var manager = new UserManager <ApplicationUser>(store); var user = new ApplicationUser { UserName = fEmail, Email = fEmail }; var result = manager.Create(user, Password); if (result.Succeeded) { var mUser = new User(fName, sName, fEmail, Role, bDate, user.Id); context.MyUsers.Add(mUser); context.SaveChanges(); } //**// //Aleksander Tabor fName = "Aleksander"; sName = "Tabor"; fEmail = "*****@*****.**"; Password = "******"; Role = "User"; bDate = DateTime.ParseExact("1996-01-26", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); var store2 = new UserStore <ApplicationUser>(context); var manager2 = new UserManager <ApplicationUser>(store); var user2 = new ApplicationUser { UserName = fEmail, Email = fEmail }; var result2 = manager.Create(user2, Password); if (result2.Succeeded) { var mUser2 = new User(fName, sName, fEmail, Role, bDate, user2.Id); context.MyUsers.Add(mUser2); context.SaveChanges(); } //**// //**// //Michał Paszkowiak fName = "Michał"; sName = "Paszkowiak"; fEmail = "*****@*****.**"; Password = "******"; Role = "User"; bDate = DateTime.ParseExact("1997-12-28", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); var store3 = new UserStore <ApplicationUser>(context); var manager3 = new UserManager <ApplicationUser>(store); var user3 = new ApplicationUser { UserName = fEmail, Email = fEmail }; var result3 = manager.Create(user3, Password); if (result3.Succeeded) { var mUser3 = new User(fName, sName, fEmail, Role, bDate, user3.Id); context.MyUsers.Add(mUser3); context.SaveChanges(); } //**// //Collect #1 var newCollection = new Collect(); newCollection.DateOfInitiative = DateTime.ParseExact("2017-09-12", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); newCollection.OwnerId = 1; newCollection.RecipientId = 2; newCollection.Name = "Zbiórka dla Aleksandra"; newCollection.Amount = 100; context.Collections.Add(newCollection); context.SaveChanges(); //**// //Collect #2 var newCollection2 = new Collect(); newCollection2.DateOfInitiative = DateTime.ParseExact("2017-09-24", "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); newCollection2.OwnerId = 2; newCollection2.RecipientId = 3; newCollection2.Name = "Zbiórka dla Michała"; newCollection2.Amount = 200; context.Collections.Add(newCollection2); context.SaveChanges(); //**// //Collect #1 _suffix //ModelUser modelUser = context.ModelUsers.Find(1); //var collect = modelUser.Collects.First(); //collect.Name = collect.Name + "_suffix"; //context.SaveChanges(); //**// //CollectUser #1 var newCollectionUsers = new CollectUser(); newCollectionUsers.UserId = 1; newCollectionUsers.CollectId = 1; context.CollectionsUsers.Add(newCollectionUsers); context.SaveChanges(); //**// //CollectUser #2 var newCollectionUsers2 = new CollectUser(); newCollectionUsers2.UserId = 2; newCollectionUsers2.CollectId = 2; context.CollectionsUsers.Add(newCollectionUsers2); context.SaveChanges(); //**// //CollectGift #1 var newCollectionGifts = new CollectGift(); newCollectionGifts.UserId = 1; newCollectionGifts.CollectId = 1; newCollectionGifts.Name = "Kurtka"; context.CollectionsGifts.Add(newCollectionGifts); context.SaveChanges(); //**// ////CollectGiftRatings #1 //var newCollectionGiftRatings = new CollectGiftRating(); //newCollectionGiftRatings.UserId = 1; //newCollectionGiftRatings.GiftId = 1; //newCollectionGiftRatings.TheBestRating = true; //context.CollectionsGiftRatings.Add(newCollectionGiftRatings); //context.SaveChanges(); ////**// //Seed base.Seed(context); }
public void CollectUserAdd(CollectUser collectuser) { _unitOfWork.CollectUserRepository.Add(collectuser); _unitOfWork.SaveChanges(); }
// //CollectsUsersController // public CollectUser GetCollectUser(int collectuserId) { CollectUser collectuser = _unitOfWork.CollectUserRepository.GetById(collectuserId); return(collectuser); }
public CollectUsersListBoxViewModel GetCollectUsersListBoxViewModelPost(int collectId, CollectUsersListBoxViewModel person) { Collect collect = GetCollect(collectId); int RecipientId = _unitOfWork.MyUserRepository.Get().SingleOrDefault(c => c.Id == collect.RecipientId).Id; using (var collectService = new CollectsService()) { person.UsersList = collectService.AllPersonsList(RecipientId); person.CollectId = collect.Id; person.CollectName = collect.Name; person.RecipientName = _unitOfWork.MyUserRepository.Get().SingleOrDefault(c => c.Id == collect.RecipientId).Name; } if (person.UsersListIds != null) { List <SelectListItem> selectedItems = person.UsersList.Where(p => person.UsersListIds.Contains(int.Parse(p.Value))).ToList(); //ViewBag.Message = "Wybrani użytkownicy:"; foreach (var selectedItem in selectedItems) { selectedItem.Selected = true; //ViewBag.Message += "\\n" + selectedItem.Text; if (!_unitOfWork.CollectUserRepository.Get().Any(c => c.UserId.ToString() == selectedItem.Value && c.CollectId == collect.Id)) { var newCollectionUsers = new CollectUser(); newCollectionUsers.UserId = Int32.Parse(selectedItem.Value); newCollectionUsers.CollectId = collect.Id; _unitOfWork.CollectUserRepository.Add(newCollectionUsers); _unitOfWork.SaveChanges(); } } foreach (var item in person.UsersList) { if (!item.Selected) { if (_unitOfWork.CollectUserRepository.Get().Any(c => c.UserId.ToString() == item.Value && c.CollectId == collect.Id)) { _unitOfWork.CollectUserRepository.Delete(_unitOfWork.CollectUserRepository.Get().SingleOrDefault(c => c.UserId.ToString() == item.Value && c.CollectId == collect.Id).Id); _unitOfWork.SaveChanges(); } } } } else { foreach (var item in person.UsersList) { if (!item.Selected) { if (_unitOfWork.CollectUserRepository.Get().Any(c => c.UserId.ToString() == item.Value && c.CollectId == collect.Id)) { _unitOfWork.CollectUserRepository.Delete(_unitOfWork.CollectUserRepository.Get().SingleOrDefault(c => c.UserId.ToString() == item.Value && c.CollectId == collect.Id).Id); _unitOfWork.SaveChanges(); } } } } return(person); }