public async Task CalendarUserModel_Save_DoesSave() { // Arrange Random rnd = new Random(); CalendarUserModel calendarUserModel = new CalendarUserModel(); calendarUserModel.Color = Guid.NewGuid().ToString(); calendarUserModel.NameInCalendar = Guid.NewGuid().ToString(); calendarUserModel.IsVisibleInCalendar = rnd.Next(100) < 50; calendarUserModel.SiteId = rnd.Next(1, 255); // Act await calendarUserModel.Create(DbContext); CalendarUser dbCalendarUser = DbContext.CalendarUsers.AsNoTracking().First(); List <CalendarUser> userList = DbContext.CalendarUsers.AsNoTracking().ToList(); //List<CalendarUserVersions> versionList = DbContext.CalendarUsersVersions.AsNoTracking().ToList(); // Assert Assert.NotNull(dbCalendarUser); Assert.AreEqual(1, userList.Count()); Assert.AreEqual(calendarUserModel.Color, dbCalendarUser.Color); Assert.AreEqual(calendarUserModel.IsVisibleInCalendar, dbCalendarUser.IsVisibleInCalendar); Assert.AreEqual(calendarUserModel.NameInCalendar, dbCalendarUser.NameInCalendar); Assert.AreEqual(calendarUserModel.SiteId, dbCalendarUser.SiteId); }
public async Task Update(eFormCaseManagementPnDbContext _dbContext) { CalendarUser calendarUser = _dbContext.CalendarUsers.FirstOrDefault(x => x.Id == Id); if (calendarUser == null) { throw new NullReferenceException($"Could not find Calendar User with id {Id}"); } calendarUser.Color = Color; calendarUser.IsVisibleInCalendar = IsVisibleInCalendar; calendarUser.NameInCalendar = NameInCalendar; calendarUser.SiteId = SiteId; calendarUser.WorkflowState = WorkflowState; if (_dbContext.ChangeTracker.HasChanges()) { calendarUser.UpdatedByUserId = UpdatedByUserId; calendarUser.UpdatedAt = DateTime.Now; calendarUser.Version += 1; _dbContext.CalendarUserVersions.Add(MapVersions(_dbContext, calendarUser)); await _dbContext.SaveChangesAsync(); } }
// GET: Families/Delete public async Task <IActionResult> Delete(Guid?id) { CalendarUser user = await _userManager.GetUserAsync(User); if (id == null) { return(NotFound()); } var family = await _context.Families .FirstOrDefaultAsync(m => m.ID == id); if (family == null) { return(NotFound()); } if (family.CreatorID != user.Id.ToString()) { TempData["tryDeleteMessage"] = "Only creator of group has right to delete it"; return(RedirectToAction("Index", "Families")); } return(View(family)); }
public async Task <List <Family> > GetUserFamilies(CalendarUser user) { List <Family> families = await _context.Families.Where(f => f.FamilyMembers.Contains(user)) .Include(f => f.FamilyMembers).ToListAsync(); return(families); }
private async void BtnOk_OnClicked(object sender, EventArgs e) { ApiServices apiServices = new ApiServices(); var calendarUser = new CalendarUser() { Email = Settings.UserName, Password = Settings.Password }; var workTask = new WorkTask() { TitleWorkTask = "Handla", CalendarUserEmail = "*****@*****.**", }; bool response = await apiServices.RegisterWorkTask(workTask); if (!response) { await DisplayAlert("Alert", "Something wrong...", "Cancel"); } else { await DisplayAlert("Skapat!", "Din aktivitet har skapats", "Ok"); Navigation.InsertPageBefore(new HomePage(), this); await Navigation.PopAsync(); } }
public async Task <Family> GetUserFamily(CalendarUser user) { Family family = await _context.Families.Where(f => f.FamilyMembers.Contains(user)) .Include(f => f.FamilyMembers).FirstOrDefaultAsync(); return(family); }
public ActionResult <Calendar> Delete(string orgID, [FromBody] CalendarUser calendarUser) { Calendar calendar = new Calendar(); string sql = string.Format("select * from tlbCalendar WHERE date = '{0}' and orgID={1}", calendarUser.Date, orgID); int capacity; try { SqlConnection connection = new SqlConnection(Params.connetionString); connection.Open(); SqlCommand command = new SqlCommand(sql, connection); SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { calendar.EmployeesArriving = dataReader["EmployeesArriving"].ToString().Trim(); calendar.SittingCapacity = dataReader["SittingCapacity"].ToString().Trim(); calendar.Date = dataReader["Date"].ToString().Trim(); calendar.WaitingList = dataReader["WaitingList"].ToString().Trim(); } dataReader.Close(); if (calendar.Date != null) { capacity = int.Parse(calendar.SittingCapacity); if (calendar.EmployeesArriving == null || !calendar.EmployeesArriving.Contains(calendarUser.Id)) { return(NotFound()); } else { calendarUser.UpdateCapacity(connection, ++capacity, orgID); string idToRemove = string.Format("{0};", calendarUser.Id); calendar.EmployeesArriving = calendar.EmployeesArriving.Replace(idToRemove, ""); calendarUser.UpdateArrivingID(connection, calendar.EmployeesArriving, orgID); if (!string.IsNullOrEmpty(calendar.WaitingList)) { calendarUser.UpdateCapacity(connection, --capacity, orgID); string idFromWaitingList = calendar.WaitingList.Split(";")[0]; string idToAdd = string.Format("{0};", idFromWaitingList); calendar.EmployeesArriving += idToAdd; calendarUser.UpdateArrivingID(connection, calendar.EmployeesArriving, orgID); calendar.WaitingList = calendar.WaitingList.Replace(idToAdd, ""); calendarUser.UpdateWaitingList(connection, calendar.WaitingList, orgID); calendarUser.SendWaitingListEmail(connection, idFromWaitingList, calendar.Date, orgID); } } string employeesName = calendarUser.GetComingEmployeesNames(calendar.EmployeesArriving, connection, orgID); command.Dispose(); connection.Close(); calendar.EmployeesArriving = employeesName; return(new OkObjectResult(JsonConvert.SerializeObject(calendar))); } return(BadRequest()); } catch (Exception e) { return(new BadRequestObjectResult(e.Message)); } }
public void AddAccesToCalendar( MedicalStuffId medicalStuffId) { _calendarUsers.Add(CalendarUser.CreateNew( Id, medicalStuffId, MedicalStuffRole.Nurse )); }
// GET: Families public async Task <IActionResult> Index() { CalendarUser user = await _userManager.GetUserAsync(User); var families = await _familyService.GetUserFamilies(user); ViewBag.deletingMessage = TempData["tryDeleteMessage"]; ViewBag.editingMessage = TempData["tryEditMessage"]; return(View(families)); }
private async Task AddCalendarUser(CalendarUser calendarUser) { var connection = _sqlConnectionFactory.GetOpenConnection(); var procedure = "[InsertOrUpdateCalendarUser]"; Thread.Sleep(100); await connection.QueryAsync(procedure, calendarUser.CreateNew(), commandType : CommandType.StoredProcedure); await _domainEventsDispatcher.DispatchEventsAsync(calendarUser.GetDomainEvents()); }
public async Task <bool> RegisterCalendarUser(CalendarUser calendarUser) { var json = JsonConvert.SerializeObject(calendarUser); var httpClient = new HttpClient(); var content = new StringContent(json, Encoding.UTF8, "application/json"); httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", Settings.Accesstoken); var calendarUserApiUrl = "http://calendaradhd.azurewebsites.net/api/CalendarUsers/PostCalendarUser"; var response = await httpClient.PostAsync(calendarUserApiUrl, content); return(response.IsSuccessStatusCode); }
public async Task <IActionResult> Index(FamilyViewModel model) { ModelState.Clear(); CalendarUser user = await _userManager.GetUserAsync(User); Guid guidID = Guid.Parse(model.SelectedFamily); var family = await _familyService.GetFamilyById(guidID); model = await UpdateModel(user, family, model); return(View(model)); }
public ActionResult <Calendar> Get(string orgID, string date) { string sql = string.Format("select * from tlbCalendar WHERE date = '{0}' and OrgID={1}", date, orgID); Calendar calendar = new Calendar(); try { SqlConnection connection = new SqlConnection(Params.connetionString); connection.Open(); SqlCommand command = new SqlCommand(sql, connection); SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { calendar.EmployeesArriving = dataReader["EmployeesArriving"].ToString(); calendar.Date = dataReader["Date"].ToString(); } dataReader.Close(); command.Dispose(); if (calendar.Date != null) { if (calendar.EmployeesArriving != null) { CalendarUser user = new CalendarUser(); calendar.EmployeesArriving = user.GetComingEmployeesNames(calendar.EmployeesArriving, connection, orgID); connection.Close(); return(new OkObjectResult(JsonConvert.SerializeObject(calendar))); } connection.Close(); return(new OkResult()); } else { connection.Close(); } Office office = new Office(); office.GetOfficeById(orgID); calendar.OrgID = office.ID; calendar.Date = date; calendar.ParkingCapacity = office.ParkingAmount; calendar.SittingCapacity = office.OfficeCapacity; calendar.EmployeesArriving = null; calendar.WaitingList = null; calendar.InsertDate(); return(NotFound()); } catch (Exception) { return(new BadRequestResult()); } }
public async Task <IActionResult> EditUser() { CalendarUser user = await _userManager.GetUserAsync(User); EditUserViewModel model = new EditUserViewModel(); model.Name = user.Name; model.Lastname = user.Lastname; model.Email = user.Email; model.Phone = user.PhoneNumber; model.Birthday = user.Birthday; return(View(model)); }
//method generate options list, which contains all users groups(families) public async Task <List <SelectListItem> > FamiliesSelectList(CalendarUser user, Family family) { var familiesList = await _context.Families.Where(f => f.FamilyMembers.Contains(user)).AsNoTracking() .OrderBy(f => f.Name) .Select(n => new SelectListItem { Value = n.ID.ToString(), Text = n.Name, Selected = (n.ID == family.ID) }).ToListAsync(); return(familiesList); }
public async Task <IActionResult> Create(FamilyViewModel model) { if (ModelState.IsValid) { CalendarUser user = await _userManager.GetUserAsync(User); model.Family.FamilyMembers.Add(user); model.Family.CreatorID = user.Id; model.Family.ID = Guid.NewGuid(); Family family = model.Family; await _familyService.WriteToDB(family); return(RedirectToAction(nameof(Index))); } return(View(model)); }
public async Task <IActionResult> Register(UserViewModel model) { if (ModelState.IsValid) { if (await EmailAlreadyInUse(model.Email)) { ViewBag.ErrorEmailMessage = ($"email {model.Email} is already in use"); return(View("Index")); } if (await PhoneAlreadyInUse(model.Phone)) { ViewBag.ErrorPhoneMessage = ($"phone number {model.Phone} is already in use"); return(View("Index")); } CalendarUser newUser = new CalendarUser() { Name = model.Name, Lastname = model.Lastname, UserName = model.Name, Email = model.Email, PhoneNumber = model.Phone, Birthday = model.Birthday }; var result = await _userManager.CreateAsync(newUser, model.ConfirmPassword); if (result.Succeeded) { if (EmailCheckForAdmin(model.Email)) { await _userManager.AddToRoleAsync(newUser, "Admin"); } if (CheckForAge(model)) { await _userManager.AddToRoleAsync(newUser, "Adult"); } else { await _userManager.AddToRoleAsync(newUser, "Kid"); } TempData["successMessage"] = "Your registration was successfull, now you can login"; return(RedirectToAction("Login")); } } return(View("~/Views/Registration/Index.cshtml", model)); }
public async Task CalendarUserModel_Delete_DoesDelete() { // Arrange Random rnd = new Random(); CalendarUser calendarUser = new CalendarUser(); calendarUser.Color = Guid.NewGuid().ToString(); calendarUser.IsVisibleInCalendar = rnd.Next(100) < 50; calendarUser.NameInCalendar = Guid.NewGuid().ToString(); calendarUser.SiteId = rnd.Next(1, 255); calendarUser.WorkflowState = Constants.WorkflowStates.Created; DbContext.CalendarUsers.Add(calendarUser); await DbContext.SaveChangesAsync(); //CalendarUserVersion calendarUserVer = new CalendarUserVersion(); // Act CalendarUserModel calendarUserModel = new CalendarUserModel(); calendarUserModel.Color = calendarUser.Color; calendarUserModel.IsVisibleInCalendar = calendarUser.IsVisibleInCalendar; calendarUserModel.NameInCalendar = calendarUser.NameInCalendar; calendarUserModel.SiteId = calendarUser.SiteId; calendarUserModel.Id = calendarUser.Id; await calendarUserModel.Delete(DbContext); CalendarUser dbCalendarUser = DbContext.CalendarUsers.AsNoTracking().First(); List <CalendarUser> userList = DbContext.CalendarUsers.AsNoTracking().ToList(); //List<CalendarUserVersions> versionList = DbContext.CalendarUsersVersions.AsNoTracking().ToList(); // Assert Assert.NotNull(dbCalendarUser); Assert.AreEqual(1, userList.Count()); Assert.AreEqual(calendarUserModel.Color, dbCalendarUser.Color); Assert.AreEqual(calendarUserModel.IsVisibleInCalendar, dbCalendarUser.IsVisibleInCalendar); Assert.AreEqual(calendarUserModel.NameInCalendar, dbCalendarUser.NameInCalendar); Assert.AreEqual(calendarUserModel.SiteId, dbCalendarUser.SiteId); Assert.AreEqual(Constants.WorkflowStates.Removed, dbCalendarUser.WorkflowState); }
public async Task Create(eFormCaseManagementPnDbContext _dbContext) { CalendarUser calendarUser = new CalendarUser(); calendarUser.Color = Color; calendarUser.IsVisibleInCalendar = IsVisibleInCalendar; calendarUser.NameInCalendar = NameInCalendar; calendarUser.SiteId = SiteId; calendarUser.RelatedEntityId = RelatedEntityId; calendarUser.Version = 1; calendarUser.CreatedAt = DateTime.Now; _dbContext.CalendarUsers.Add(calendarUser); await _dbContext.SaveChangesAsync(); _dbContext.CalendarUserVersions.Add(MapVersions(_dbContext, calendarUser)); await _dbContext.SaveChangesAsync(); }
//mapper for view model, when active user group is changed private async Task <FamilyViewModel> UpdateModel(CalendarUser user, Family family, FamilyViewModel model) { var selectedUsers = await _famControlService.MembersSelectList(family); var allUsers = await _famControlService.UsersSelectList(family); var selectedFamilies = await _famControlService.FamiliesSelectList(user, family); model.SelectedUser = user.Id;; model.SelectedMember = " "; model.SelectedFamily = family.ID.ToString(); model.Family = family; model.AllUsers = allUsers; model.AllMembers = selectedUsers; model.AllFamilies = selectedFamilies; return(model); }
public Calendar( string title, List <MedicalStuffId> nursesIds) { Id = new CalendarId(Guid.NewGuid()); _title = title; AddDomainEvent(new CalendarCreatedDomainEvent(Id)); if (nursesIds.Any()) { _calendarUsers = new List <CalendarUser>(); nursesIds.ForEach(_ => { _calendarUsers.Add(CalendarUser.CreateNew(Id, _, MedicalStuffRole.Nurse)); }); } }
//method retrive users phone and sends sms by Twilio service private ActionResult SendSms(CalendarUser user, string smsTxt) { string userPhone = user.PhoneNumber; string accountSid = Configuration["ACCOUNT_SEED"]; string authToken = Configuration["AUTH_TOKKEN"]; TwilioClient.Init(accountSid, authToken); var to = new PhoneNumber(userPhone); var from = new PhoneNumber("+15756399489"); var message = MessageResource.Create( to: to, from: from, body: smsTxt ); NLogger.Info($"text message:{smsTxt} send to phone {userPhone} on {DateTime.Now}"); return(Content(message.Sid)); }
public async Task <IActionResult> IndexAsync() { CalendarUser user = await _userManager.GetUserAsync(User); List <Family> userFamilies = await _familyService.GetUserFamilies(user); // check if user has created group, otherwise redirected to create view if (userFamilies.Count() == 0) { TempData["warningMessage"] = "In order to visit Calendar,please create family group first"; return(RedirectToAction("Create", "Families")); } // generate view model of user families and members in SelectedItemLists, set active group var family = userFamilies.First(); var model = new FamilyViewModel(); model = await UpdateModel(user, family, model); return(View(model)); }
public async Task <IActionResult> Edit(Guid?id) { CalendarUser user = await _userManager.GetUserAsync(User); if (id == null) { return(NotFound()); } var family = await _familyService.GetFamilyById(id); if (family == null) { return(NotFound()); } if (family.CreatorID != user.Id.ToString()) { TempData["tryEditMessage"] = "Only creator of group has right to edit it"; return(RedirectToAction("Index", "Families")); } return(View(family)); }
// method generate sms mesage text, retrive event user, who need to receive SMS and pass it to SendSms method private async Task SmsMessage(Event smsEvent) { CalendarUser userFrom = await _familyService.GetUser(smsEvent.MessageFrom); string smsText = smsEvent.Subject + " " + smsEvent.Description + " " + userFrom.Name; if (smsEvent.SendToAll)// check if all group members should receive sms message { var users = await _familyService.GetFamilyUsers(smsEvent.Family.ID); foreach (var member in users) { SendSms(member, smsText); } } else { CalendarUser user = await _familyService.GetUser(smsEvent.MesageTo); SendSms(user, smsText); } }
public async Task <bool> RegisterUser(string email, string password, string confirmPassword) { var registerModel = new RegisterModel() { Email = email, Password = password, ConfirmPassword = confirmPassword }; var calendarUser = new CalendarUser() { Email = email, Password = password }; var httpClient = new HttpClient(); var json = JsonConvert.SerializeObject(registerModel); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync("http://calendaradhd.azurewebsites.net/api/Account/Register", content); await RegisterCalendarUser(calendarUser); return(response.IsSuccessStatusCode); }
public ActionResult Put(string orgID, [FromBody] CalendarUser calendarUser) { string sql = string.Format("select * from tlbCalendar WHERE date = '{0}' and OrgID={1}", calendarUser.Date, orgID); string waitingList = null, date = null; try { SqlConnection connection = new SqlConnection(Params.connetionString); connection.Open(); SqlCommand command = new SqlCommand(sql, connection); SqlDataReader dataReader = command.ExecuteReader(); while (dataReader.Read()) { waitingList = dataReader["WaitingList"].ToString().Trim(); date = dataReader["Date"].ToString().Trim(); } dataReader.Close(); command.Dispose(); if (date != null) { if (waitingList == null || !waitingList.Contains(calendarUser.Id)) { waitingList += calendarUser.Id + ";"; sql = string.Format("update tlbCalendar set WaitingList='{0}' WHERE date = '{1}'", waitingList, calendarUser.Date); command = new SqlCommand(sql, connection); command.ExecuteNonQuery(); command.Dispose(); } } connection.Close(); return(NoContent()); } catch (Exception) { return(new BadRequestResult()); } }
public async Task <List <EventViewModel> > GetAllEvents(CalendarUser user) { //create list of IDes of all user groups(families) var userFamilies = await _familyService.GetUserFamilies(user); List <Guid> evtList = new List <Guid>(); foreach (var item in userFamilies) { evtList.Add(item.ID); } // query for all events which depends to user's families var events = await _context.Events.Where(evt => evtList.Contains(evt.Family.ID)).Include(evt => evt.Family).ToListAsync(); // create and map new list of events view models List <EventViewModel> model = new List <EventViewModel>(); foreach (var item in events) { EventViewModel evnt = new EventViewModel(); evnt.ID = item.ID; evnt.Subject = item.Subject; evnt.Description = item.Description; evnt.Start = item.Start; evnt.End = item.End; evnt.MessageFrom = item.MessageFrom; evnt.MessageTo = item.MesageTo; evnt.FamilyID = item.Family.ID.ToString(); evnt.FamilyName = item.Family.Name; evnt.EventStatus = item.EventStatus.ToString(); evnt.ThemeColor = item.ThemeColor; evnt.IsFullDay = item.IsFullDay; evnt.SendReminder = item.SendReminder; evnt.SendToAll = item.SendToAll; model.Add(evnt); } return(model); }
public async Task <IActionResult> EditUser(EditUserViewModel model) { if (ModelState.IsValid) { CalendarUser user = await _userManager.GetUserAsync(User); user.UserName = model.Name; user.Name = model.Name; user.Lastname = model.Lastname; user.Email = model.Email; user.PhoneNumber = model.Phone; user.Birthday = model.Birthday; var userUpdate = await _userManager.UpdateAsync(user); if (!userUpdate.Succeeded) { ViewBag.ErrorMessage = "Something gone wrong, please try again"; return(View()); } return(View("UserUpdated")); } return(View(model)); }
public async Task <IActionResult> Login(SignInViewModel model, string returnUrl) { CalendarUser user = await _userManager.Users.Where(u => u.Email == model.Email).FirstOrDefaultAsync(); if (!ModelState.IsValid || user == null) { ViewBag.AuthError = "Wrong sign in details"; return(View("Login", model)); } var result = await _signInManager.PasswordSignInAsync(user.Name, model.Password, false, false); if (result.Succeeded) { if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } return(RedirectToAction("Index", "Home")); } ViewBag.AuthError = "Wrong sign in details"; return(View("Login", model)); }
private void AddorUpdateUsercalender(int userid, string claendarid,string color) { try { if (!string.IsNullOrEmpty(claendarid) && userid != 0) { var usercalender = _calendarRepository.GetCalendarUserByUserId(userid); if (usercalender != null) { usercalender.CalendarId = int.Parse(claendarid); usercalender.Color = color; _calendarRepository.UpdateCalendarUser(usercalender); } else { var objcal = new CalendarUser(); objcal.CalendarId = int.Parse(claendarid); objcal.UserId = userid; objcal.Color = color; objcal.Created = DateTime.Now; _calendarRepository.SaveCalendarUser(objcal); } } } catch (Exception ex) { string msg = ex.Message; } }
public void SaveCalendarUser(CalendarUser obj) { db.CalendarUsers.Add(obj); db.SaveChanges(); }
public void UpdateCalendarUser(CalendarUser obj) { db.Entry(obj).State = EntityState.Modified; db.SaveChanges(); }