public void AddCounselor(Counselor counselor) { var parmsCollection = new ParmsCollection(); this.unitOfWork.DbContext.Counselors.Add(counselor); this.unitOfWork.DbContext.SaveChanges(); }
public async Task <IActionResult> Create([Bind("ID,FirstName,MiddleName,LastName,Nickname,SIN")] Counselor counselor) { try { if (ModelState.IsValid) { _context.Add(counselor); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException dex) { if (dex.InnerException.Message.Contains("IX_Counselors_SIN")) { ModelState.AddModelError("SIN", "Unable to save changes. Remember, you cannot have duplicate SIN numbers."); } else { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } } return(View(counselor)); }
public ActionResult DeleteConfirmed(int id) { Counselor counselor = db.Counselors.Find(id); db.Counselors.Remove(counselor); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task DeleteCounselor(int portalId, int counselorId) { Counselor dbCounselor = await GetCounselorById(portalId, counselorId); dbCounselor.IsActive = false; dbCounselor.IsDeleted = true; await Context.SaveChangesAsync(); }
public Treatment GenerateTreatment(Client client, Counselor counselor) { var treatment = new Treatment(); treatment.StartDate = DateTime.Now; treatment.Client = client; treatment.Counselor = counselor; treatment.Steps = GenerateSteps(); return treatment; }
public ActionResult Edit([Bind(Include = "ID,LastName,FirstName,Phone")] Counselor counselor) { if (ModelState.IsValid) { db.Entry(counselor).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(counselor)); }
public async Task <ActionResult <Counselor> > GetCounselor(int portalId, int counselorId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Counselor counselor = await _counselorRepository.GetCounselorById(portalId, counselorId); return(Ok(counselor)); }
public ActionResult Create([Bind(Include = "ID,LastName,FirstName,Phone")] Counselor counselor) { if (ModelState.IsValid) { db.Counselors.Add(counselor); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(counselor)); }
public async Task <ActionResult <Counselor> > CreateCounselor(int portalId, [FromBody] CounselorModel counselor) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Counselor newCounselor = await _counselorRepository.CreateCounselor(portalId, counselor); return(Ok(newCounselor)); }
public async Task <Counselor> GetCounselorById(int portalId, int counselorId) { Counselor dbCounselor = await Context.Counselors.FirstOrDefaultAsync(x => x.PortalId == portalId && x.Id == counselorId && !x.IsDeleted); if (dbCounselor == null) { throw new Exception("This counselor does not exist"); } return(dbCounselor); }
protected virtual void OnIsCltOpeningChanged(DependencyPropertyChangedEventArgs e) { if (IsCltOpening) { int line = Core.SelectedStart.Line; int column = Core.SelectedStart.Column; IMRATextItemInfo lineitem = UI_Main.GetItem(line); MRATextItemView lineview = lineitem?.View; if (lineview == null) { return; } #region Canvas Top { Point p = lineview.TranslatePoint(new Point(0, 0), CV_Cover); if (p.Y + lineview.ActualHeight + UI_CltBox.ActualHeight < ActualHeight) { Canvas.SetTop(UI_CltBox, p.Y + lineview.ActualHeight); } else { Canvas.SetTop(UI_CltBox, p.Y - UI_CltBox.ActualHeight); } } #endregion #region Canvas Left { Rect rect = lineview.GetColumnActualRect(column); double x = rect.X; if (UI_Main.UI_Stack != null) { x -= UI_Main.UI_Stack.HorizontalOffset; } x = Math.Max(x, 0.0); x = Math.Min(x, ActualWidth - UI_CltBox.ActualWidth); Canvas.SetLeft(UI_CltBox, x); } #endregion IEnumerable <IMRACltItem> cltsrcs = Counselor.GetCltItems(Core.GetInputContext()); UI_CltBox.SetCltSources(cltsrcs); ITextPosition pos = Core.SelectedStart.NextSeek(); UI_CltBox.SetInputText(String.Empty); UI_CltBox.SetInputText(pos.Item.ToString()); UI_CltBox.Visibility = Visibility.Visible; } else { UI_CltBox.Visibility = Visibility.Hidden; } }
// GET: Counselors/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Counselor counselor = db.Counselors.Find(id); if (counselor == null) { return(HttpNotFound()); } return(View(counselor)); }
internal void CltOpen(string inputtext) { if (IsCltOpening) { return; } if (Counselor == null) { return; } if (!Counselor.CanCltOpen(Core.GetInputContext(), inputtext)) { return; } IsCltOpening = true; }
public async Task <Counselor> UpdateCounselor(int portalId, int counselorId, CounselorModel counselor) { Counselor dbCounselor = await GetCounselorById(portalId, counselorId); dbCounselor.FirstName = counselor.FirstName.Trim(); dbCounselor.LastName = counselor.LastName.Trim(); dbCounselor.StartingBalance = counselor.StartingBalance; dbCounselor.IsActive = counselor.IsActive; dbCounselor.UpdatedDate = DateTimeOffset.Now; dbCounselor.UserId = counselor.UserId; dbCounselor.CabinId = counselor.CabinId; await Context.SaveChangesAsync(); return(dbCounselor); }
internal void CltCloseByBackspace(string backspacetext) { if (!IsCltOpening) { return; } if (Counselor == null) { return; } if (!Counselor.CanCltCloseByBackspace(Core.GetInputContext(), backspacetext)) { return; } IsCltOpening = false; }
private static void AddOneCouncelour(CampSleepawayContext context) { Counselor counselor = new Counselor { FirstName = "Gösta Ekman" }; context.Counselors.Add(counselor); Cabin rock = context.Cabins.Find(1); rock.Counselor = counselor; //moonbase.Counselor = counselor; context.SaveChanges(); }
private static void CreateNewCabinAndCounselour() { using (CampSleepawayContext context = new CampSleepawayContext()) { string bigfirstname = MenuUtils.AskForString("Vad heter Lägerledaren i förnamn?"); string biglastname = MenuUtils.AskForString("Vad heter Lägerledaren i efternamn?"); string cabinName = MenuUtils.AskForString("Vad ska kabinen heta?"); Counselor counselor = new Counselor { FirstName = bigfirstname, LastName = biglastname }; Cabin cabin = new Cabin { Name = cabinName, Counselor = counselor }; context.Cabins.Add(cabin); context.SaveChanges(); } }
public async Task <Counselor> CreateCounselor(int portalId, CounselorModel counselor) { Counselor newCounselor = new Counselor { PortalId = portalId, FirstName = counselor.FirstName.Trim(), LastName = counselor.LastName.Trim(), StartingBalance = counselor.StartingBalance, CreatedBy = counselor.CreatedBy, CreatedDate = DateTimeOffset.Now, UpdatedDate = DateTimeOffset.Now, UserId = counselor.UserId, CabinId = counselor.CabinId, IsActive = true, IsDeleted = false }; await Context.Counselors.AddAsync(newCounselor); await Context.SaveChangesAsync(); return(newCounselor); }
public OpenToAssign(Counselor counselor, bool isOpen) { Counselor = counselor; IsOpen = isOpen; }
public async Task <IActionResult> Edit(int id, string[] selectedOptions, Byte[] RowVersion, string chkRemoveImage, IFormFile thePicture) { var camperToUpdate = await _context.Campers .Include(c => c.Compound) .Include(c => c.Counselor) .Include(c => c.CamperDiets) .ThenInclude(cd => cd.DietaryRestriction) .FirstOrDefaultAsync(c => c.ID == id); //Check that you got it or exit with a not found error if (camperToUpdate == null) { return(NotFound()); } //If Staff Role, check that they created this Camper //Note: They should never get here, but just in case... if (User.IsInRole("Staff")) { if (User.Identity.Name != camperToUpdate.CreatedBy) { //Cannot edit this camper ModelState.AddModelError("", "Edit Not Allowed. As Staff, you can only edit campers that you put into the system."); PopulateDropDownLists(camperToUpdate); PopulateAssignedDietaryRestrictionData(camperToUpdate); return(View("EditStaff", camperToUpdate)); } } //Update the medical history UpdateCamperDietaryRestrictions(selectedOptions, camperToUpdate); if (await TryUpdateModelAsync <Camper>(camperToUpdate, "", p => p.FirstName, p => p.MiddleName, p => p.LastName, p => p.DOB, p => p.Gender, p => p.CompoundID, p => p.Phone, p => p.eMail, p => p.CounselorID)) { try { //For the image if (chkRemoveImage != null) { camperToUpdate.imageContent = null; camperToUpdate.imageMimeType = null; camperToUpdate.imageFileName = null; } else { if (thePicture != null) { string mimeType = thePicture.ContentType; long fileLength = thePicture.Length; if (!(mimeType == "" || fileLength == 0))//Looks like we have a file!!! { if (mimeType.Contains("image")) { using (var memoryStream = new MemoryStream()) { await thePicture.CopyToAsync(memoryStream); camperToUpdate.imageContent = memoryStream.ToArray(); } camperToUpdate.imageMimeType = mimeType; camperToUpdate.imageFileName = thePicture.FileName; } } } } //Put the original RowVersion value in the OriginalValues collection for the entity _context.Entry(camperToUpdate).Property("RowVersion").OriginalValue = RowVersion; _context.Update(camperToUpdate); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } catch (RetryLimitExceededException /* dex */) { ModelState.AddModelError("", "Unable to save changes after multiple attempts. Try again, and if the problem persists, see your system administrator."); } catch (DbUpdateConcurrencyException ex)// Added for concurrency { var exceptionEntry = ex.Entries.Single(); var clientValues = (Camper)exceptionEntry.Entity; var databaseEntry = exceptionEntry.GetDatabaseValues(); if (databaseEntry == null) { ModelState.AddModelError("", "Unable to save changes. The Camper was deleted by another user."); } else { var databaseValues = (Camper)databaseEntry.ToObject(); if (databaseValues.FirstName != clientValues.FirstName) { ModelState.AddModelError("FirstName", "Current value: " + databaseValues.FirstName); } if (databaseValues.MiddleName != clientValues.MiddleName) { ModelState.AddModelError("MiddleName", "Current value: " + databaseValues.MiddleName); } if (databaseValues.LastName != clientValues.LastName) { ModelState.AddModelError("LastName", "Current value: " + databaseValues.LastName); } if (databaseValues.DOB != clientValues.DOB) { ModelState.AddModelError("DOB", "Current value: " + String.Format("{0:d}", databaseValues.DOB)); } if (databaseValues.Phone != clientValues.Phone) { ModelState.AddModelError("Phone", "Current value: " + String.Format("{0:(###) ###-####}", databaseValues.Phone)); } if (databaseValues.eMail != clientValues.eMail) { ModelState.AddModelError("eMail", "Current value: " + databaseValues.eMail); } if (databaseValues.Gender != clientValues.Gender) { ModelState.AddModelError("Gender", "Current value: " + databaseValues.Gender); } //For the foreign key, we need to go to the database to get the information to show if (databaseValues.CompoundID != clientValues.CompoundID) { Compound databaseCompound = await _context.Compounds.SingleOrDefaultAsync(i => i.ID == databaseValues.CompoundID); ModelState.AddModelError("CompoundID", $"Current value: {databaseCompound?.Name}"); } //A little extra work for the nullable foreign key. No sense going to the database and asking for something //we already know is not there. if (databaseValues.CounselorID != clientValues.CounselorID) { if (databaseValues.CounselorID.HasValue) { Counselor databaseCounselor = await _context.Counselors.SingleOrDefaultAsync(i => i.ID == databaseValues.CounselorID); ModelState.AddModelError("CounselorID", $"Current value: {databaseCounselor?.FullName}"); } else { ModelState.AddModelError("CounselorID", $"Current value: None"); } } ModelState.AddModelError(string.Empty, "The record you attempted to edit " + "was modified by another user after you received your values. The " + "edit operation was canceled and the current values in the database " + "have been displayed. If you still want to save your version of this record, click " + "the Save button again. Otherwise click the 'Back to List' hyperlink."); camperToUpdate.RowVersion = (byte[])databaseValues.RowVersion; ModelState.Remove("RowVersion"); } } catch (DbUpdateException dex) { if (dex.InnerException.Message.Contains("IX_Campers_eMail")) { ModelState.AddModelError("eMail", "Unable to save changes. Remember, you cannot have duplicate eMail addresses."); } else { ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists see your system administrator."); } } } PopulateDropDownLists(camperToUpdate); PopulateAssignedDietaryRestrictionData(camperToUpdate); if (User.IsInRole("Staff"))//Decide which version of the view to send { return(View("EditStaff", camperToUpdate)); } else { return(View(camperToUpdate)); } }
public static async Task <ScoreSummaryByDepartmentViewModel> GetAsync(UnitOfWork unitOfWork, Counselor counselor) { // 学生无改动时直接从缓存中取出,学生信息有改动时进行修改 handleLock.WaitOne(); var summaryVMDictionary = unitOfWork.Cache.DepartmentScoreSummaries(); var model = await summaryVMDictionary.GetAsync(counselor.Department); if (model == null) { model = new ScoreSummaryByDepartmentViewModel { DepartmentID = counselor.Department, CounselorName = counselor.Name, StudentCount = await unitOfWork.StudentRepository.SizeByDepartment(counselor.Department), MaxScore = await unitOfWork.StudentRepository.HighestScoreByDepartment(counselor.Department), AverageScore = await unitOfWork.StudentRepository.AverageScoreByDepartment(counselor.Department), ScoreBandCount = new ScoreBandCountViewModel() { HigherThan90 = await unitOfWork.StudentRepository.ScoreHigherThanByDepartment(90, counselor.Department), HigherThan75 = await unitOfWork.StudentRepository.ScoreHigherThanByDepartment(75, counselor.Department), HigherThan60 = await unitOfWork.StudentRepository.ScoreHigherThanByDepartment(60, counselor.Department), NotTested = await unitOfWork.StudentRepository.CountNotTestedByDepartment(counselor.Department) } }; model.ScoreBandCount.Failed = model.StudentCount - model.ScoreBandCount.NotTested - model.ScoreBandCount.HigherThan60; await summaryVMDictionary.SetAsync(counselor.Department, model); } return(model); }
public void AddCounselor(Counselor counselor) { this.loginDataAccess.AddCounselor(counselor); }
public void AddToCounselors(Counselor counselor) { base.AddObject("Counselors", counselor); }
public static void Initialize(IServiceProvider serviceProvider) { using (var context = new CampOrnoContext( serviceProvider.GetRequiredService <DbContextOptions <CampOrnoContext> >())) { //Create sample data with some random values Random random = new Random(); string[] firstNames = new string[] { "Fred", "Barney", "Wilma", "Betty" }; string[] kidNames = new string[] { "Woodstock", "Sally", "Violet", "Charlie", "Lucy", "Linus", "Franklin", "Marcie", "Schroeder" }; string[] lastNames = new string[] { "Stovell", "Jones", "Bloggs", "Flintstone", "Rubble", "Brown", "Smith", "Daniel" }; string[] nicknames = new string[] { "Hightower", "Wizard", "Kingfisher", "Prometheus", "Broomspun", "Shooter", "Chuckles" }; string[] compounds = new string[] { "Nestlings", "Fledglings", "Sharpies" }; string[] diets = new string[] { "Peanuts", "Shellfish", "Gluten", "Lactose", "Halal" }; string[] genders = new string[] { "M", "F", "N", "T", "O" }; string[] activities = new string[] { "Canoeing", "Archery", "Ice Fishing", "Karate", "Coding" }; //For seeding pictures string[] pictures = new string[] { "Barney.png", "blankProfile.png", "Fred.png", "Pebbles.png", "Wilma.png" }; //For Part 5 //Activities if (!context.Activities.Any()) { //loop through the array of Compound names foreach (string a in activities) { Activity act = new Activity() { Name = a }; context.Activities.Add(act); } context.SaveChanges(); } //Dietary Restrictions if (!context.DietaryRestrictions.Any()) { //loop through the array of Compound names foreach (string d in diets) { DietaryRestriction diet = new DietaryRestriction() { Name = d }; context.DietaryRestrictions.Add(diet); } context.SaveChanges(); } //Compounds if (!context.Compounds.Any()) { //loop through the array of Compound names foreach (string c in compounds) { Compound compound = new Compound() { Name = c }; context.Compounds.Add(compound); } context.SaveChanges(); } //Counselors if (context.Counselors.Count() == 0) { List <Counselor> counselors = new List <Counselor>(); foreach (string lastName in lastNames) { foreach (string firstname in firstNames) { //Construct some counselor details Counselor newCounselor = new Counselor() { FirstName = firstname, LastName = lastName, MiddleName = lastName[1].ToString().ToUpper(), SIN = random.Next(213214131, 989898989).ToString(), }; counselors.Add(newCounselor); } } //Now give a few of them nicknames. //We don't want any duplicates so choose one counselor //for each nickname int numNames = nicknames.Count(); int numCounselors = counselors.Count(); for (int i = 0; i < numNames; i++) { counselors[random.Next(0, numNames)].Nickname = nicknames[i]; } //Now add your list into the DbSet context.Counselors.AddRange(counselors); context.SaveChanges(); } //Create collections of the primary keys int[] counselorIDs = context.Counselors.Select(a => a.ID).ToArray(); int counselorIDCount = counselorIDs.Count(); int[] compoundIDs = context.Compounds.Select(a => a.ID).ToArray(); int compoundIDCount = compoundIDs.Count(); int genderCount = genders.Count(); int pictureCount = pictures.Count(); //Campers if (!context.Campers.Any()) { // Start birthdate for randomly produced campers // We will subtract a random number of days from today DateTime startDOB = DateTime.Today; List <Camper> campers = new List <Camper>(); int toggle = 1; //Used to alternate assigning counselors foreach (string lastName in lastNames) { foreach (string kidname in kidNames) { //Construct some employee details Camper newCamper = new Camper() { FirstName = kidname, LastName = lastName, MiddleName = kidname[1].ToString().ToUpper(), DOB = startDOB.AddDays(-random.Next(1480, 5800)), Gender = genders[random.Next(genderCount)], //Uncomment these lines to seed profile pictures //imageContent = imageToBytes("wwwroot/pictures/" + pictures[random.Next(pictureCount)]), //imageMimeType = "image/png", //imageFileName = "Profile.png", eMail = (kidname.Substring(0, 2) + lastName + random.Next(11, 111).ToString() + "@outlook.com").ToLower(), Phone = Convert.ToInt64(random.Next(2, 10).ToString() + random.Next(213214131, 989898989).ToString()), CompoundID = compoundIDs[random.Next(compoundIDCount)] }; if (toggle % 2 == 0)//Every second camper gets a lead counselor assigned { newCamper.CounselorID = counselorIDs[random.Next(counselorIDCount)]; } toggle++; campers.Add(newCamper); } } //Now add your list into the DbSet context.Campers.AddRange(campers); context.SaveChanges(); } //Create collections of the primary keys int[] camperIDs = context.Campers.Select(a => a.ID).ToArray(); int camperIDCount = camperIDs.Count(); int[] dietaryRestrictionIDs = context.DietaryRestrictions.Select(a => a.ID).ToArray(); int dietaryRestrictionIDCount = dietaryRestrictionIDs.Count(); //For Part 5 int[] activityIDs = context.Activities.Select(a => a.ID).ToArray(); int activityIDCount = activityIDs.Count(); //For Part 5 //CamperActivities - the Intersection //Add an activity to every second Camper if (!context.CamperActivities.Any()) { int toggle = 1; //Used to alternate for (int i = 0; i < camperIDCount; i++) { if (toggle % 2 == 0)//Every second camper { CamperActivity ds = new CamperActivity() { CamperID = camperIDs[i], ActivityID = activityIDs[random.Next(activityIDCount)] }; context.CamperActivities.Add(ds); } toggle++; } context.SaveChanges(); } //CamperDiets - the Intersection //Add a few restrictions to every second Camper if (!context.CamperDiets.Any()) { int toggle = 1; //Used to alternate for (int i = 0; i < camperIDCount; i++) { if (toggle % 2 == 0)//Every second camper { CamperDiet ds = new CamperDiet() { CamperID = camperIDs[i], DietaryRestrictionID = dietaryRestrictionIDs[random.Next(dietaryRestrictionIDCount)] }; context.CamperDiets.Add(ds); } toggle++; } context.SaveChanges(); } //CounselorCompounds - the Intersection //Add a compound to each counselor if (!context.CounselorCompounds.Any()) { foreach (int i in counselorIDs) { CounselorCompound cc = new CounselorCompound() { CompoundID = compoundIDs[random.Next(compoundIDCount)], CounselorID = i }; context.CounselorCompounds.Add(cc); } } context.SaveChanges(); } }
public IActionResult AddCounselor([FromBody] Counselor counselor) { this.loginBusinessAccess.AddCounselor(counselor); return(Ok(counselor)); }
public static Counselor CreateCounselor(int ID, byte[] rowVersion) { Counselor counselor = new Counselor(); counselor.Id = ID; counselor.RowVersion = rowVersion; return counselor; }