public ActionResult AddActivity(AddActivityViewModel activityViewModel, string userName, int childId) { // check if logged in if (Session["parent"] == null) { return(View("Login")); } ActivityModel activity = new ActivityModel(); activity.Seconds = activityViewModel.Steps / 10; activity.Carrots = activityViewModel.Minutes; activity.Date = activityViewModel.Date; if (activity.Date.CompareTo(DateTime.Now.Date) > 0) { TempData["CustomError"] = "You cannot add activity for a future date"; return(RedirectToAction("AddActivity", "Parent", activityViewModel)); } activity.ChildId = childId; activityDAL.AddActivity(activity); return(RedirectToAction("Dashboard")); }
public ActionResult Edit(string ActivityId) { int AmActivityId = 0; Int32.TryParse(ActivityId, out AmActivityId); if (AmActivityId == 0 || DMLObj.GetActivityById(AmActivityId) == null) { return(View("Error")); } AMActivity EditAct = DMLObj.GetActivityById(AmActivityId); var OrgsObj = DMLObj.GetOrganizationList(); ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObj); ViewBag.ActivityTypes = DMLObj.GetAllActivityTypes(); var ProcessObj = DMLObj.GetProcessList(); ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObj); AddActivityViewModel EditObj = new AddActivityViewModel(); EditObj.Name = EditAct.Name; EditObj.Description = EditAct.Description; EditObj.Id = EditAct.Id; EditObj.SelectedOrganizationStr = DMLObj.GetActivityOrgsByActIdAsString(AmActivityId); EditObj.SelectedProcessesStr = DMLObj.GetActivityProcessesByActIdAsString(AmActivityId); EditObj.TypeId = EditAct.TypeId; return(View(EditObj)); }
public ActionResult AddActivity(string userName) { // check if logged in if (Session["parent"] == null) { return(View("Login")); } ChildModel child = childDAL.GetChild(userName); child.Mascot = mascotDAL.GetMascot(child); AddActivityViewModel activityViewModel = new AddActivityViewModel(); activityViewModel.UserName = userName; activityViewModel.Child_Id = child.Child_Id; activityViewModel.Mascot = child.Mascot; if (TempData["CustomError"] != null) { ModelState.AddModelError("futureDate", TempData["CustomError"].ToString()); } return(View("AddActivity", activityViewModel)); }
public IActionResult activities(AddActivityViewModel newactivity) { int?userid = HttpContext.Session.GetInt32("user_id"); int id = (int)userid; if (userid == null) { RedirectToAction("Index"); } if (ModelState.IsValid) { if (newactivity.Date < DateTime.Today) { TempData["error"] = "Date should be future-date"; return(View("AddActivity")); } Planner newactive = new Planner { UserId = id, Title = newactivity.Title, Date = newactivity.Date, Time = newactivity.Time, Duration = newactivity.Duration, Hours = newactivity.Hours, Description = newactivity.Description }; _context.Add(newactive); _context.SaveChanges(); return(RedirectToAction("activity", "Home", new { activityID = newactive.PlannerId })); } return(View("AddActivity")); }
public ActionResult AddActivity(AddActivityViewModel viewModel) { if (activitiesService.IsValidModelState()) { Activity activity = new Activity(); activity.ActivityId = 0; activity.Duration = viewModel.Duration; activity.Name = viewModel.Name; activity.Price = viewModel.Price; if (activitiesService.IsExistingActivity(a => a.Name == activity.Name)) { return(View(viewModel)); } bool hasSuccessfullySaved = activitiesService.Add(activity); if (hasSuccessfullySaved) { TempData["SuccessfullMessage"] = "Activity added successfully!"; return(RedirectToAction("ViewActivities", "Activities")); } else { TempData["ErrorMessage"] = "There was a server error during the save of the activity. Try again!"; return(RedirectToAction("Index", "Home")); } } return(View(viewModel)); }
public IActionResult Add() { List <Child> children = context.Children.ToList(); AddActivityViewModel addActivityViewModel = new AddActivityViewModel(children); return(View(addActivityViewModel)); }
public AddActivityView(List <EnquiryModel> enquiries, ActivityModel activity) { InitializeComponent(); DataContext = ViewModel = new AddActivityViewModel(enquiries, activity); Owner = Application.Current.MainWindow; Loaded += OnAddActivityViewLoaded; }
public AddActivityView(EnquiryModel enquiryModel, ActivityModel activity = null) { InitializeComponent(); DataContext = ViewModel = new AddActivityViewModel(enquiryModel, activity); ViewModel.PropertyChanged += ViewModelOnPropertyChanged; Owner = Application.Current.MainWindow; Loaded += OnAddActivityViewLoaded; }
public IActionResult AddActivity(AddActivityViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var newId = this.activity.AddActivity(new ActivityModel { Activity = model.Activity }); TempData.AddSuccessMessage($"Activity: {model.Activity} with ID: {newId} has been added successfully."); return(RedirectToAction(nameof(Index))); }
public IActionResult Add(AddActivityViewModel addActivityViewModel, string[] selectedChildren) { if (ModelState.IsValid) { var userId = _userManager.GetUserId(User); Activity newActivity = new Activity() { Name = addActivityViewModel.Name, StartTime = addActivityViewModel.StartTime, EndTime = addActivityViewModel.EndTime, IsOnline = addActivityViewModel.IsOnline, Location = addActivityViewModel.Location }; context.Activities.Add(newActivity); foreach (var childIdString in selectedChildren) { int childId = int.Parse(childIdString); ChildActivity newChildActivity = new ChildActivity { Activity = newActivity, ChildId = childId, ActivityId = newActivity.Id, Status = "toDo" }; context.ChildActivites.Add(newChildActivity); } context.SaveChanges(); return(Redirect("Index")); } List <Child> children = context.Children.ToList(); AddActivityViewModel wrongAddActivityViewModel = new AddActivityViewModel(children); wrongAddActivityViewModel.Name = addActivityViewModel.Name; wrongAddActivityViewModel.StartTime = addActivityViewModel.StartTime; wrongAddActivityViewModel.EndTime = addActivityViewModel.EndTime; wrongAddActivityViewModel.IsOnline = addActivityViewModel.IsOnline; wrongAddActivityViewModel.Location = addActivityViewModel.Location; wrongAddActivityViewModel.ChildIds = addActivityViewModel.ChildIds; return(View("Add", wrongAddActivityViewModel)); }
public IActionResult Create(AddActivityViewModel model) { if (ModelState.IsValid) { Activity newSession = new Activity { title = model.title, sessionDateTime = model.sessionDateTime, duration = model.duration, durationAnnotation = model.durationAnnotation, description = model.description, created_at = DateTime.UtcNow, updated_at = DateTime.UtcNow, userID = (int)HttpContext.Session.GetInt32("userID") }; _context.activities.Add(newSession); _context.SaveChanges(); return(RedirectToAction("Splash")); } else { Console.WriteLine("THIS IS THE ERORR"); return(View("AddActivity", model)); } }
public ActionResult Add([Bind(Include = "Id,Name,Description,TypeId,SelectedOrganizationStr,SelectedProcessesStr")] AddActivityViewModel AddObj) { if (!ModelState.IsValid) { var OrgsObj = DMLObj.GetOrganizationList(); ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObj); ViewBag.ActivityTypes = DMLObj.GetAllActivityTypes(); var ProcessObj = DMLObj.GetProcessList(); ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObj); return(View(AddObj)); } var OrgsList = DMLObj.FindOrgsForAddActivityByStringIds(AddObj.SelectedOrganizationStr); if (OrgsList.Count() == 0) { var OrgsObj = DMLObj.GetOrganizationList(); ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObj); ViewBag.ActivityTypes = DMLObj.GetAllActivityTypes(); var ProcessObj = DMLObj.GetProcessList(); ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObj); ModelState.AddModelError("SelectedOrganizationStr", "هیچ سازمان معتبری انتخاب نشده است"); return(View(AddObj)); } var ProcessesList = DMLObj.FindProcessesForAddActivityByStringIds(AddObj.SelectedProcessesStr); if (ProcessesList.Count() == 0) { var OrgsObj = DMLObj.GetOrganizationList(); ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObj); ViewBag.ActivityTypes = DMLObj.GetAllActivityTypes(); var ProcessObj = DMLObj.GetProcessList(); ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObj); ModelState.AddModelError("SelectedProcessesStr", "هیچ فرآیند معتبری انتخاب نشده است"); return(View(AddObj)); } var selectedActType = DMLObj.GetActivityTypeById(AddObj.TypeId); if (selectedActType == null) { var OrgsObj = DMLObj.GetOrganizationList(); ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObj); ViewBag.ActivityTypes = DMLObj.GetAllActivityTypes(); var ProcessObj = DMLObj.GetProcessList(); ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObj); ModelState.AddModelError("TypeId", "هیچ نوع فعالیت معتبری انتخاب نشده است"); return(View(AddObj)); } bool resAdd = false; var addedActivity = DMLObj.AddNewActivity(new AMActivity { Name = AddObj.Name, Description = AddObj.Description, ActivityItems = null, TypeId = AddObj.TypeId, Type = selectedActType }, out resAdd); if (resAdd && DMLObj.AddNewActivityRelation(OrgsList, ProcessesList, addedActivity) > 0) { return(View("Success")); } var OrgsObjp = DMLObj.GetOrganizationList(); ViewBag.AllOrganizations = AutoMapper.Mapper.Map <IEnumerable <AMOrganization>, IEnumerable <JsonOrganizationViewModel> >(OrgsObjp); ViewBag.ActivityTypes = DMLObj.GetAllActivityTypes(); var ProcessObjp = DMLObj.GetProcessList(); ViewBag.AllProcesses = AutoMapper.Mapper.Map <IEnumerable <AMProcess>, IEnumerable <JsonProcessViewModel> >(ProcessObjp); return(View("Error")); }