} // create a new relation passed on params public async Task <Account> ChangeTypeAccount(Account account) { //salvare la lista degli user con cui un account ha una referenza if (int.TryParse(account.Id, out int accountId)) { List <SqlAssignement> sqlAssignements = dbContext.SqlAssignements.Where(x => x.SqlAccount.Id == accountId).ToList(); ObjectEmptyFromDb(sqlAssignements); List <SqlUser> sqlUsers = new List <SqlUser>(); Assignement assa = new Assignement(); foreach (var ass in sqlAssignements) { sqlUsers.Add(ass.SqlUser); await DeleteAssignement(ass.Id.ToString()); }// fatto questo dovrei avere la lista degli user salvata e eliminare le referenze tra user e account await DeleteAsync(account.Id);// elimino l'account var acc = await CreateAccountAsync(account);//creo il nuovo account foreach (var user in sqlUsers) { assa.User = mapper.Map <User>(user); await dbContext.SaveChangesAsync(); assa.Account = acc; await dbContext.SaveChangesAsync(); await SetAssignementAsync(assa); } return(account); // da verificare tutti i metodi che fanno, specie come procedono delete, create, set assignement e tutto il processo //fare un bel debug per tutti, anche staticamente } throw new NullReferenceException(); } // allow to change type of accont with different call at delete and create method
internal void AssignEnd(Assignement work, bool succed) { switch (work.TypeAssignement) { case TypeAssignement.Buy: Buy buy = ((Buy)work); DesactivateAll(buy.List_Item, List_ItemNeedBuy); Controller.UpdateMemory(buy.List_UpdateShopInfo, buy.Shop); break; case TypeAssignement.Sell: Sell sell = ((Sell)work); DesactivateAll(sell.List_Item, List_ItemNeedSell); Controller.UpdateMemory(sell.List_UpdateShopInfo, sell.Shop); break; case TypeAssignement.SearchInfo: SearchInfo search = (SearchInfo)work; foreach (var infoShop in search.Dict_Shop_ListInfoItem) { Controller.UpdateMemory(infoShop.Value, infoShop.Key); } b_SearchInfo = false; break; } }
} // return a collection of user by email of account public async Task <Assignement> SetAssignementAsync(Assignement assignement) { if (int.TryParse(assignement.User.Id, out int idUser) && int.TryParse(assignement.Account.Id, out int accountId)) { var sqlAccount = dbContext.SqlAccounts.FirstOrDefault(x => x.Id == accountId); ObjectEmptyFromDb(sqlAccount); var sqlUser = dbContext.SqlUsers.FirstOrDefault(x => x.Id == idUser); ObjectEmptyFromDb(sqlUser); if (sqlAccount == null || sqlUser == null) { throw new NullReferenceException(Resource.ObjectNullFromDb); } assignement.CreationDate = DateTime.UtcNow; assignement.LastEdit = DateTime.UtcNow; var sqlAssign = mapper.Map <SqlAssignement>(assignement); sqlAssign.SqlAccount = sqlAccount; sqlAssign.SqlUser = sqlUser; dbContext.SqlAssignements.Add(sqlAssign); await dbContext.SaveChangesAsync(); return(mapper.Map <Assignement>(sqlAssign)); } throw new NullReferenceException(Resource.InvalidOperation); } // create new relation between user and account
public Task BindModelAsync(Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext bindingContext) { var discriminator = bindingContext.ValueProvider.GetValue("Account.AccountType").ToString(); var myType = AccountExtensions.Type(discriminator); var r = new Assignement { Account = Account.GetInstanceOf(myType) }; r.Account.Id = bindingContext.ValueProvider.GetValue("Account.Id").ToString(); r.Account.Nickname = bindingContext.ValueProvider.GetValue("Account.Nickname").ToString(); r.Account.Email = bindingContext.ValueProvider.GetValue("Account.Email").ToString(); r.User.Name = bindingContext.ValueProvider.GetValue("User.Name").ToString(); r.User.Surname = bindingContext.ValueProvider.GetValue("User.Surname").ToString(); //var result = Account.GetInstanceOf(discriminator); //result.Id = bindingContext.ValueProvider.GetValue("Account.Id").ToString(); //result.Nickname = bindingContext.ValueProvider.GetValue("Account.Nickname").ToString(); //result.Email = bindingContext.ValueProvider.GetValue("Account.Email").ToString(); // result.User.Id = bindingContext.ValueProvider.GetValue("User.Id").ToString(); //bindingContext.ModelState.SetModelValue( // bindingContext.ModelName, ); bindingContext.Result = ModelBindingResult.Success(r); return(Task.CompletedTask); //return ModelBindingResult.Success(result); }
public async Task <IActionResult> Edit(int id, [Bind("Id,CourseId,Description,StudentId,TeacherId,Grade")] Assignement assignement) { string student = assignement.StudentId; if (id != assignement.Id) { return(NotFound()); } if (ModelState.IsValid) { try { assignement.StudentId = student; _context.Update(assignement); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AssignementExists(assignement.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); }
public ActionResult DeleteConfirmed(int id) { Assignement assignement = db.Assignements.Find(id); db.Assignements.Remove(assignement); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <bool> RemoveAssignement(Assignement assignement) { if (int.TryParse(assignement.Id, out int assignementId)) { var aAssignement = await dbContext.SqlAssignements.FirstOrDefaultAsync(x => x.Id == assignementId); dbContext.Remove(aAssignement); await dbContext.SaveChangesAsync(); return(true); } return(false); }
public async Task <bool> ResetAssignementAsync(Assignement assignement) { if (int.TryParse(assignement.Id, out int assignementId)) { SqlAssignement sqlAssignement = await dbContext.SqlAssignements.FirstOrDefaultAsync(x => x.Id == assignementId); sqlAssignement.DeactivationDate = null; await dbContext.SaveChangesAsync(); return(true); } return(false); }
public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Assignement assignement = db.Assignements.Find(id); if (assignement == null) { return(HttpNotFound()); } return(View(assignement)); }
public async Task <Assignement> SetAssignementAsync(string accountId, List <string> usersId) { Assignement assignement = new Assignement { Account = await provider.GetById(accountId) }; foreach (var us in usersId) { assignement.User = await provider.GetUserById(us); await provider.SetAssignementAsync(assignement); } return(assignement); }
public ActionResult Create([Bind(Include = "id,assignmentname,periode")] Assignement assignement, string select) { int selectid = Convert.ToInt32(select); if (ModelState.IsValid) { Course c = db.Courses.Where(p => p.id == selectid).FirstOrDefault(); db.Assignements.Add(assignement); c.assignement.Add(assignement); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(assignement)); }
public async Task <Assignement> SetAssignementAsync(string userId, List <string> accountsId) { Assignement assignement = new Assignement { User = await provider.GetById(userId) }; foreach (var acc in accountsId) { Account account = await provider.GetAccountById(acc); assignement.Account = account; await provider.SetAssignementAsync(assignement); } return(assignement); }
public async Task <IActionResult> NewUser(AccountantTypes accountantTypes) { Account account = await accountHelper.GetById(acccountId); ViewBag.accountType = account.AccountType.ToString(); string ids = userId; TempData["Id"] = ids; await Task.Delay(0); Assignement assignement = new Assignement { Account = Account.GetInstanceOf(AccountantTypes.Admin) }; return(View(mapper.Map <CreateUser>(assignement))); }
public async Task <Assignement> CreateUserAndDefaultAccount(Assignement assignement) { User user = assignement.User; Account account = assignement.Account; account.IsDefault = true; var fullUser = await userHelper.CreateUserAsync(user); var fullAccount = await accountHelper.CreateAccountAsync(account); List <string> accountsId = new List <string> { fullAccount.Id }; return(await userHelper.SetAssignementAsync(fullUser.Id, accountsId)); }
private IEnumerator SecAssignementRoutine(Assignement w) { DoSecAssignement = true; DoMainAssignement = false; yield return(new WaitForSeconds(0.1f)); //go to Batiment de prod w.SetController(Controller); yield return(w.DoWork()); List_Assignement.Remove(w); DoSecAssignement = false; }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Assignement assignement = db.Assignements.Find(id); if (assignement == null) { return(HttpNotFound()); } IQueryable c = db.Courses;// we must send the complete listof corses to the veiw it can be throw IQueryable ViewBag.Course = c; return(View(assignement)); }
public ActionResult Edit(int id, string assignmentname, string periode, string select) { Assignement assign = db.Assignements.Where(c => c.id == id).FirstOrDefault(); if (ModelState.IsValid) { assign.assignmentname = assignmentname; assign.periode = periode; int selectid = Convert.ToInt32(select); Course cou = db.Courses.Where(c => c.id == selectid).FirstOrDefault(); //cou.assignement.Clear(); cou.assignement.Add(assign); db.Entry(assign).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(assign)); }
public async Task CheckIfAssignementIsDeleted() { //Arrange var users = await userProvider.UsersAsync(); User user = users.FirstOrDefault(); var assignements = await userProvider.AssignementsByUserIdAsync(user.Id); Assignement assignement = assignements.FirstOrDefault(); //Act bool deleted = await userProvider.DeleteAssignement(assignement.Id); var reset = await userProvider.ResetAssignementAsync(assignement); //Arrange Assert.True(deleted); Assert.True(reset); }
public async Task CheckSetAssignementAsync() { var accounts = await accountProvider.AccountsAsync(); Account account = accounts.FirstOrDefault(); var users = await accountProvider.UsersAsync(); User user = users.FirstOrDefault(); Assignement assignement = new Assignement() { Account = account, User = user, }; var created = await accountProvider.SetAssignementAsync(assignement); Assert.NotNull(created); Assert.IsType <Assignement>(created); Assert.True(await accountProvider.RemoveAssignement(created)); }
public async Task CkeckIfAssignamentIsCreated() { //Arrange var users = await userProvider.UsersAsync(); User user = users.FirstOrDefault(); var accounts = await userProvider.AccountsAsync(); Account account = accounts.FirstOrDefault(); Assignement assignement = new Assignement() { Account = account, User = user }; //Act var created = await userProvider.SetAssignementAsync(assignement); //Assert Assert.NotNull(created); Assert.IsType <Assignement>(created); Assert.True(await userProvider.RemoveAssignement(created)); }
public void Update() { if (List_Assignement.Count > 0 && !DoSecAssignement) { DoMainAssignement = false; var assT = List_Assignement.First(); if (assT != null) { CurrentAssignement = assT; StartCoroutine(SecAssignementRoutine(assT)); DoSecAssignement = true; } } else { if (!DoSecAssignement && !DoMainAssignement && MainAssignement != null) { DoMainAssignement = true; StartCoroutine(MainAssignementRoutine()); } } }
public async Task <ActionResult> Create([Bind("Id,Course,Description,Grade")] Assignement assignement) { User teacher = await GetCurrentUserAsync(); var nvc = Request.Form; string user_post = nvc["Course"]; var sameuser = _context.Course.FirstOrDefault(u => u.Name == user_post); assignement.Course = sameuser; char[] separators = new char[] { ' ', ';' }; string[] users = assignement.Course.UsersId.Split(separators, StringSplitOptions.RemoveEmptyEntries); if (assignement.Course.UsersId != "") { foreach (var user in users) { Assignement _assignement = new Assignement(); _assignement.Course = assignement.Course; _assignement.Description = assignement.Description; _assignement.Grade = assignement.Grade; _assignement.TeacherId = teacher.Id; _assignement.StudentId = user; _context.Add(_assignement); await _context.SaveChangesAsync(); } return(RedirectToAction(nameof(Index))); } else { return(RedirectToAction(nameof(Error))); } }
internal void Set_MainAssign(Assignement MainAssignement) { WorkComponement?.Set_MainAssign(MainAssignement); }
public void Set_MainAssign(Assignement ass) { MainAssignement = ass; MainAssignement.SetController(Controller); }
internal void Assign(Assignement assignementV2) { WorkComponement?.AssignSec(assignementV2); }
internal void AssignSec(Assignement assignementV2) { List_Assignement.Add(assignementV2); }
public void Remove_MainAssign() { MainAssignement = null; }