示例#1
0
        public IActionResult AddActivity(EditActivityViewModel activity)
        {
            activity.ActivityToAdd.Date = DateTime.Now;
            activity.ListOfProducts     = new SelectList(
                repository.Products, "ProductID", "Name");

            ModelState.Remove("ProductQuantity");
            ModelState.Remove("ProductID");

            if (ModelState.IsValid)
            {
                repository.SaveActivity(activity.ActivityToAdd);
                repository.SaveProductsInActivity(activity.ActivityProducts,
                                                  activity.ActivityToAdd);

                if (activity.ActivityToAdd.Type.Equals("Admission"))
                {
                    TempData["message"] = $"Dodano przyjęcie na magazyn nr " +
                                          $"{activity.ActivityToAdd.ActivityID}";
                }
                else
                {
                    TempData["message"] = $"Dodano wydanie z magazynu nr " +
                                          $"{activity.ActivityToAdd.ActivityID}";
                }
                return(RedirectToAction("ShowActivities",
                                        new { activityType = activity.ActivityToAdd.Type }));
            }
            else
            {
                return(View("EditActivity", activity));
            }
        }
        public async Task  ActivityDetailsUpdate(Activity fvActivity, EditActivityViewModel amendedDetails)
        {
            if (fvActivity.Name != amendedDetails.Name)
            {
                await UpdateActivityAsync("name", amendedDetails.Id, amendedDetails.Name);
            }

            if (fvActivity.IsPrivate != amendedDetails.IsPrivate)
            {
                await UpdateActivityAsync("private", amendedDetails.Id, amendedDetails.IsPrivate? "true" : "false");
            }

            if (fvActivity.Description != amendedDetails.Description)
            {
                await UpdateActivityAsync("description", amendedDetails.Id, amendedDetails.Description);
            }

            if (fvActivity.IsCommute != amendedDetails.IsCommute)
            {
                await UpdateActivityAsync("commute", amendedDetails.Id, amendedDetails.IsCommute? "true" : "false");
            }

            fvActivity.Name        = amendedDetails.Name;
            fvActivity.IsPrivate   = amendedDetails.IsPrivate;
            fvActivity.IsCommute   = amendedDetails.IsCommute;
            fvActivity.Description = amendedDetails.Description;

            //        _unitOfWork.Activity.UpdateActivity(fvActivity);
            _unitOfWork.CRUDRepository.Update <Activity>(fvActivity);
            _unitOfWork.Complete();
        }
        public ActionResult EditActivity(EditActivityViewModel viewModel)
        {
            if (activitiesService.IsValidModelState())
            {
                bool isExistingActivity = activitiesService.IsExistingActivity(a => a.ActivityId == viewModel.ActivityId);
                if (isExistingActivity == false)
                {
                    TempData["ErrorMessage"] = "There is no existing activity with that id. You can add one if you want.";
                    return(RedirectToAction("ViewActivities", "Activities"));
                }

                Activity dbActivity = activitiesService.GetById(viewModel.ActivityId);
                dbActivity.ActivityId = viewModel.ActivityId;
                dbActivity.Duration   = viewModel.Duration;
                dbActivity.Name       = viewModel.Name;
                dbActivity.Price      = viewModel.Price;
                bool hasSuccessfullySaved = activitiesService.Edit(dbActivity);
                if (hasSuccessfullySaved)
                {
                    TempData["SuccessfullMessage"] = "Activity edited successfully";
                    return(RedirectToAction("ViewActivities", "Activities"));
                }
                else
                {
                    TempData["ErrorMessage"] = "Server error when trying to update the activity";
                    return(RedirectToAction("Index", "Home"));
                }
            }

            return(View(viewModel));
        }
示例#4
0
        public async Task <IActionResult> Edit(int ActivityID, EditActivityViewModel activity)
        {
            if (ActivityID != activity.ActivityID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(activity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ActivityExists(activity.ActivityID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(activity));
        }
示例#5
0
        public void ShowWindow(BaseViewModel viewModel, bool showAsDialog)
        {
            Window window = viewModel switch
            {
                // Wenn viewModel null ist -> ArgumentNullException
                null => throw new ArgumentNullException(nameof(viewModel)),

                      // Das dem Type des ViewModel entsprechende Window instanzieren
                      EmployeeViewModel _ => new MainWindow(),
                      ActivityViewModel _ => new ActivityWindow(),
                      NewActivityViewModel _ => new NewActivityWindow(),
                      EditActivityViewModel _ => new EditActivityWindow(),

                      // default -> InvalidOperationException
                      _ => throw new InvalidOperationException($"Unknown ViewModel of type '{viewModel}'"),
            };

            _windows[viewModel] = window;
            window.DataContext  = viewModel;

            if (showAsDialog)
            {
                window.ShowDialog();
            }
            else
            {
                window.Show();
            }
        }
示例#6
0
        public ViewResult AddProductToActivity(EditActivityViewModel activity)
        {
            activity.ListOfProducts = new SelectList(
                repository.Products, "ProductID", "Name");

            if (activity.ActivityProducts == null)
            {
                activity.ActivityProducts = new List <ProductValues>();
            }

            ModelState.Remove("ActivityProducts");
            ModelState.Remove("ActivityToAdd.Where");
            ModelState.Remove("ActivityToAdd.Description");

            if (ModelState.IsValid)
            {
                var prod = repository.Products
                           .Where(p => p.ProductID.Equals(activity.ProductID))
                           .FirstOrDefault();

                activity.ActivityProducts.Add(new ProductValues()
                {
                    ID       = prod.ProductID,
                    Name     = prod.Name,
                    Quantity = activity.ProductQuantity
                });
            }

            return(View("EditActivity", activity));
        }
 public EditActivityWindow()
 {
     App.LoadStaticResources(this);
     InitializeComponent();
     ViewModel = (EditActivityViewModel)this.DataContext;
     ViewModel.CloseRequest
     .ObserveOnDispatcher()
     .Subscribe(o => this.Close());
 }
        public ViewResult CreateActivity()
        {
            EditActivityViewModel model = new EditActivityViewModel
            {
                Categories = new SelectList(activityTypeRepository.ActivityTypes, "ActivityTypeId", "ActivityTypeTitle", new ActivityType())
            };

            return(View(model));
        }
        public ActionResult EditActivity(EditActivityViewModel model)
        {
            var dto = new ActivityDTO();

            dto.ActivityId  = model.ActivityId;
            dto.Name        = model.Name;
            dto.Description = model.Description;
            DataAccess.UpdateActivity(dto);
            return(RedirectToAction("Settings", "Settings"));
        }
示例#10
0
        public ViewResult EditActivity(Guid?activityId)
        {
            Activity activity = activityRepository.Activities
                                .FirstOrDefault(g => g.ActivityId == activityId);
            EditActivityViewModel model = new EditActivityViewModel
            {
                Activity   = activity,
                Categories = new SelectList(activityTypeRepository.ActivityTypes, "ActivityTypeId", "ActivityTypeTitle", new ActivityType())
            };

            return(View(model));
        }
        public ActionResult EditActivity(Guid activityId)
        {
            ViewBag.BackLinkHtml = MenuConstructor.ConstructHtmlBackLink("EditActivity", activityId);
            var model = new EditActivityViewModel();
            var dto   = DataAccess.GetActivity(activityId);

            model.Name        = dto.Name;
            model.Description = dto.Description;
            model.ImageUrl    = dto.ImageUrl;
            model.Fields      = DataAccess.GetFields(activityId);
            return(View(model));
        }
示例#12
0
        public ActionResult StoreEditActivityFromSesWishlist(EditActivityViewModel editedActivity)
        {
            //betekent dat er geen nieuwe activiteit is geselecteerd, maar aantalpersonen wel!
            //aantal personen wordt gewijzigd door item te verwijderen en opnieuw aan te maken.
            if (editedActivity.NewActivityId == 0)
            {
                editedActivity.NewActivityId = editedActivity.OldActivityId;
            }
            DeliteActivityFromSesWishlist(editedActivity.OldActivityId);
            AddItemToSesWishlist(editedActivity.NumberOfPersons, editedActivity.NewActivityId);

            ViewBag.succes = "item gewijzigd";
            return(View("Index", GetActivitiesFromSession()));
        }
示例#13
0
        public ViewResult DeleteProductFromActivity(EditActivityViewModel activity,
                                                    int activityProductId)
        {
            activity.ListOfProducts = new SelectList(
                repository.Products, "ProductID", "Name");

            ModelState.Remove("ActivityToAdd.Where");
            ModelState.Remove("ActivityToAdd.Description");
            ModelState.Remove("ProductQuantity");

            activity.ActivityProducts.RemoveAt(activityProductId);

            return(View("EditActivity", activity));
        }
示例#14
0
        public ActionResult EditActivityFromSesWishlist(int activityId)
        {
            List <WishlistViewModel> wishlist = GetActivitiesFromSession();
            WishlistViewModel        activiteit;

            if (wishlist != null)
            {
                try
                {
                    activiteit = wishlist.FindAll(x => (x.Activity.id == activityId))
                                 .Single();
                    ViewBag.succes = "item gevonden";
                    //ViewBag.dropDown = new SelectList(wishListRepo.getFilms(), "id", "title", activiteit.Activity.Filmscreenings.First().Films.id);
                    int    actionId;
                    string action;
                    int    activityType = activiteit.Activity.typeActivity;
                    switch (activityType)
                    {
                    case 1:
                        actionId         = activiteit.Activity.Filmscreenings.First().Films.id;
                        action           = "Films";
                        ViewBag.ActionId = new SelectList(wishListRepo.getFilms(), "id", "title", actionId);
                        break;

                    case 2:
                        actionId         = activiteit.Activity.Specialscreenings.First().Specials.id;
                        action           = "Specials";
                        ViewBag.ActionId = new SelectList(wishListRepo.getSpecials(), "id", "title", actionId);
                        break;

                    case 3:
                        actionId = activiteit.Activity.Restaurants.First().id;
                        action   = "Restaurants";
                        break;

                    default:
                        ViewBag.errors = "Activiteitttype niet herkent";
                        return(View("Index", GetActivitiesFromSession()));
                    }
                    EditActivityViewModel viewModel = new EditActivityViewModel(activiteit.Activity.id, actionId, action, activiteit.NumberOfPersons);
                    return(PartialView(viewModel));
                }
                catch
                {
                    ViewBag.errors = "Wishlistitem niet gevonden";
                }
            }
            ViewBag.errors = "Wishlistitem niet gevonden";
            return(View("Index", GetActivitiesFromSession()));
        }
示例#15
0
 public EditActivityPage(Activity act, PropertyChangedEventHandler propChanged)
 {
     BindingContext = new EditActivityViewModel(Navigation, act, propChanged);
     InitializeComponent();
     InitialiseElements();
     MessagingCenter.Subscribe <EditActivityViewModel, ConfirmationData>(this, EditActivityViewModel.DeleteConfirmationMessageString, async(vm, cd) =>
     {
         var answer = await DisplayAlert(cd.Title, cd.Message, cd.Accept, cd.Cancel);
         if (answer)
         {
             await vm.DeleteActivity();
             Navigation.PopModalAsync();
             await Navigation.PopModalAsync();
         }
     });
 }
示例#16
0
 public ActionResult EditActivity(EditActivityViewModel model)
 {
     model.Activity.ActivityTypeCurrent = activityTypeRepository.ActivityTypes
                                          .FirstOrDefault(p => p.ActivityTypeId.ToString() == model.CurrentCategory);
     if (ModelState.IsValid)
     {
         activityRepository.SaveActivity(model.Activity);
         TempData["message"] = string.Format("Изменения в мероприятии \"{0}\" были сохранены", model.Activity.ActivityName);
         return(RedirectToAction("ActivitiesAdministration"));
     }
     else
     {
         // Что-то не так со значениями данных
         TempData["error"] = string.Format("Ошибка при создании мероприятия \"{0}\"! ", model.Activity.ActivityName);
     }
     return(View(model));
 }
        public ActionResult EditActivity(int id)
        {
            Activity activity = activitiesService.GetById(id);

            if (activity == null)
            {
                TempData["ErrorMessage"] = "There is no activity with this id";
                return(RedirectToAction("Index", "Home"));
            }
            EditActivityViewModel viewModel = new EditActivityViewModel();

            viewModel.ActivityId = activity.ActivityId;
            viewModel.Duration   = activity.Duration;
            viewModel.Name       = activity.Name;
            viewModel.Price      = activity.Price;
            return(View(viewModel));
        }
        public ActionResult Index(EditActivityViewModel vm, int?activityId)
        {
            if (vm == null)
            {
                vm = new EditActivityViewModel();
                vm.SelectedActivity = -1;
            }

            if (activityId != null && vm.SelectedActivity <= 0)
            {
                vm.SelectedActivity = (int)activityId;
                return(Index(vm, null));
            }

            vm.ActivityInputList         = new List <ActivityInput>();
            vm.ActivityActivityInputList = new List <ActivityActivityInput>();

            vm.ActivityList = DB.Activities.Where(a => a.Active == true).ToList();


            if (vm.SelectedActivity != null && vm.SelectedActivity > 0)
            {
                //vm.ActivityInputList = DB.ActivityInputs.Where(ai => ai.Activity.ServiceActivities.Any(sa => sa.Service.ServiceId == vm.SelectedVisitType) &&
                //                                                     ai.InputType == ActivityInput.InputTypeEnum.Number)
                //                                                     .ToList();

                vm.ActivityInputList = DB.ActivityInputs.ToList();

                //vm.InputActivityList = DB.Services.Find(vm.SelectedVisitType).Activities.ToList();

                Activity tmpActivity = DB.Activities.Find(vm.SelectedActivity);

                vm.ActivityActivityInputList = tmpActivity.ActivityActivityInputs.Where(aai => aai.Active == true).ToList();

                List <int> Ids = vm.ActivityActivityInputList.Select(x => x.ActivityInput.ActivityInputId).ToList();

                vm.ActivityInputList = vm.ActivityInputList.Where(ai => Ids.Contains(ai.ActivityInputId) == false).ToList();

                //vm.ActivityInputList = DB.ActivityInputs.Where(ai => vm.ActivityInputList.Select(x => x.ActivityInputId).Contains(ai.ActivityInputId)).ToList();
            }


            return(View(vm));
        }
示例#19
0
        // GET: Activity/Edit/5
        public ActionResult Edit(Guid id)
        {
            if (!UserIsInRole("Professor"))
            {
                return(RedirectToAction("Index", "Home"));
            }
            var result = _activityQuery.Handle(new ActivityInputGetById {
                ActivityId = id
            }).Activity;
            var activity = new EditActivityViewModel
            {
                Id           = result.Id,
                Date         = result.Date.ToShortDateString(),
                Description  = result.Description,
                Value        = result.Value,
                DisciplineId = result.Discipline.Id
            };

            return(View(activity));
        }
示例#20
0
        public async Task <ActionResult> Edit(EditActivityViewModel activity)
        {
            if (ModelState.IsValid)
            {
                Activity a = _unitOfWork.CRUDRepository.GetByKey <Activity>(activity.Id, o => o.ActivityType, o => o.Athlete);

                if ((a == null) || (a.Athlete.UserId != User.Identity.GetUserId()))
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }


                StravaUpdate upd = new StravaUpdate(_unitOfWork, User.Identity.GetUserId());
                await upd.ActivityDetailsUpdate(a, activity);



                return(Json(new { success = true }));
            }
            return(PartialView("_Edit", activity));
        }
示例#21
0
        public ActionResult CreateActivity(EditActivityViewModel model)
        {
            //ActivityType type = activityTypeRepository.ActivityTypes.FirstOrDefault(x => x.ToString() );
            //activity.ActivityTypeCurrent = type;

            if (ModelState.IsValid)
            {
                model.Activity.ActivityTypeCurrent = activityTypeRepository.ActivityTypes
                                                     .FirstOrDefault(p => p.ActivityTypeId.ToString() == model.CurrentCategory);

                activityRepository.CreateActivity(model.Activity, CurrentUser);
                TempData["message"] = string.Format("Изменения в мероприятии \"{0}\" были сохранены", model.Activity.ActivityName);
                return(RedirectToAction("List", "Activity", null));
            }
            else
            {
                // Что-то не так со значениями данных
                TempData["error"] = string.Format("Ошибка при создании мероприятия \"{0}\"! ", model.Activity.ActivityName);
            }
            return(RedirectToAction("List", "Activity", null));
        }
示例#22
0
        public ActionResult Edit(EditActivityViewModel activity)
        {
            if (!UserIsInRole("Professor"))
            {
                return(RedirectToAction("Index", "Home"));
            }
            var result = _activityCommand.Handle(new ActivityInputUpdate
            {
                Id       = activity.Id,
                Activity = new UseCases.ActivityContext.Models.Activity(activity.Description, activity.DisciplineId, activity.Value, Convert.ToDateTime(activity.Date))
            });

            if (!result.IsValid)
            {
                foreach (var n in result.Notifications)
                {
                    ModelState.AddModelError(n.Key, n.Value);
                }
                return(View(activity));
            }
            return(RedirectToAction("Index", new { disciplineId = activity.DisciplineId }));
        }
        public ActionResult EditActivity(EditActivityViewModel activityvm)
        {
            // Find activity to be edited
            var activity = context.Activities.FirstOrDefault(a => a.Id == activityvm.Id);

            // Store its module for later
            var module = activity.Modules.FirstOrDefault();

            if (ModelState.IsValid)
            {
                // Edit the activity using user inputted values stored in the view model
                activity.Name        = activityvm.Name;
                activity.Description = activityvm.Description;
                activity.StartDate   = activityvm.StartDate;
                activity.EndDate     = activityvm.EndDate;

                context.Entry(activity).State = EntityState.Modified;
                context.SaveChanges();
            }

            return(RedirectToAction("TeacherCourseActivitiesPartial", new { id = module.Id }));
        }
        public IActionResult EditActivity(int ActivityId, EditActivityViewModel editActivityViewModel)
        {
            Activity updatedActivity = context.Activities.Find(ActivityId);

            updatedActivity.Name      = editActivityViewModel.Name;
            updatedActivity.StartTime = editActivityViewModel.StartTime;
            updatedActivity.EndTime   = editActivityViewModel.EndTime;
            updatedActivity.Location  = editActivityViewModel.Location;
            updatedActivity.IsOnline  = editActivityViewModel.IsOnline;

            context.SaveChanges();

            Activity             theActivity     = context.Activities.Find(ActivityId);
            List <ChildActivity> childActivities = context.ChildActivites
                                                   .Where(ca => ca.ActivityId == editActivityViewModel.ActivityId)
                                                   .Include(ca => ca.Child)
                                                   .ToList();

            ActivityDetailViewModel activityDetailViewModel = new ActivityDetailViewModel(theActivity, childActivities);

            return(View("Detail", activityDetailViewModel));
        }
示例#25
0
        public async Task <ActionResult> Edit(EditActivityViewModel model)
        {
            var activity = await db.Activities.FirstAsync(a => a.ActivityID == model.ActivityId);

            var      newStatus        = (ActivityStatus)Enum.Parse(typeof(ActivityStatus), model.Status);
            DateTime?finalizationDate = null;

            if (newStatus == ActivityStatus.Finished)
            {
                finalizationDate = DateTime.Now;
            }

            if (ModelState.IsValid)
            {
                activity.ActivityType = await db.ActivityTypes.FindAsync(model.ActivityType);

                activity.ActivityStatus = newStatus;
                activity.AssignedUser   = await db.Users.FirstAsync(u => u.Id == model.AssignedUserId);

                activity.FinalizationDate = finalizationDate;

                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "Projects", new { id = activity.Project.ProjectID }));
            }


            ViewBag.ActivityStatusList = Enum.GetValues(typeof(ActivityStatus)).Cast <ActivityStatus>().
                                         Select(a => new { Text = a.ToString(), Value = ((int)a).ToString() });
            ViewBag.ActivityTypes = db.ActivityTypes.ToList();
            ViewBag.Users         = await db.Activities.Where(a => a.ActivityID == model.ActivityId).
                                    SelectMany(a => a.Project.ApplicationUsers.
                                               Select(u => new { Text = u.UserName, Value = u.Id }))
                                    .ToListAsync();

            return(View(model));
        }
        public ActionResult EditActivity(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }


            // Find the activity to be edited
            var activity = context.Activities.Find(id);

            // Store current information to present it to the user for edit
            EditActivityViewModel vm = new EditActivityViewModel
            {
                Id          = activity.Id,
                Description = activity.Description,
                Name        = activity.Name,
                StartDate   = activity.StartDate,
                EndDate     = activity.EndDate,
                ModuleId    = activity.Modules.FirstOrDefault().Id
            };

            return(PartialView("EditActivityPartial", vm));
        }
示例#27
0
        public ActionResult FastAddActivityToSesWishlist(int activityType)
        {
            try
            {
                string action;
                switch (activityType)
                {
                case 1:
                    action           = "Films";
                    ViewBag.ActionId = new SelectList(wishListRepo.getFilms(), "id", "title", null);
                    break;

                case 2:
                    action           = "Specials";
                    ViewBag.ActionId = new SelectList(wishListRepo.getSpecials(), "id", "title", null);
                    break;

                case 3:
                    action = "Restaurants";
                    break;

                default:
                    ViewBag.errors = "Activiteitttype niet herkent";
                    return(View("Index", GetActivitiesFromSession()));
                }
                EditActivityViewModel viewModel = new EditActivityViewModel(action);
                return(PartialView(viewModel));
            }
            catch
            {
                ViewBag.errors = "Wishlistitem niet gevonden";
            }

            ViewBag.errors = "Wishlistitem niet gevonden";
            return(View("Index", GetActivitiesFromSession()));
        }
示例#28
0
        public ActionResult EditActivity(int? id)
        {
            if (id == null)
            {
                ViewBag.Error = "Inget id har angivits";
                return View("~/Views/Error/Index.cshtml");
            }

            var activity = db.Activities.FirstOrDefault(c => c.Id == id);
            if (activity == null)
            {
                ViewBag.Error = "Ingen activitet har hittats";
                return View("~/Views/Error/Index.cshtml");
            }

            Module module = activity.Module;
            if (module == null)
            {
                ViewBag.Error = "Ingen modul förälder har hittats";
                return View("~/Views/Error/Index.cshtml");
            }

            Course course = module.Course;
            if (course == null)
            {
                ViewBag.Error = "Ingen kurs flrälder har hittats";
                return View("~/Views/Error/Index.cshtml");
            }

            EditActivityViewModel model = new EditActivityViewModel();
            model.Description = activity.Description;
            model.Name = activity.Name;
            model.StartDate = (activity.StartDate != null ? (DateTime) activity.StartDate : DateTime.Today.AddDays(1));
            model.EndDate = (activity.EndDate != null ? (DateTime) activity.EndDate : DateTime.Today.AddDays(2));
            model.Deadline = activity.Deadline;

            ViewBag.Id = (int)id;

            Menu(Home: true);
            SetBreadcrumbs(
                one: new MenyItem { Link = "~/Teacher/", Text = "Se alla kurser" },
                two: new MenyItem { Link = "~/Teacher/Course/" + course.Id, Text = course.Name },
                three: new MenyItem { Link = "~/Teacher/Module/" + module.Id, Text = module.Name },
                four: new MenyItem { Link = "~/Teacher/Activity/" + activity.Id, Text = activity.Name });

            ViewBag.AtEarliest = (DateTime.Today.AddDays(1) > module.StartDate ? DateTime.Today.AddDays(1) : module.StartDate);
            ViewBag.AtLatest = (DateTime.Today.AddDays(2) < module.EndDate ? module.EndDate : DateTime.Today.AddDays(2));

            return View(model);
        }
        public NewActivityView(bool modify, ActivityModel activity)
        {
            InitializeComponent();

            BindingContext = new EditActivityViewModel(Navigation, modify, activity);
        }
示例#30
0
        public async Task <IActionResult> Edit(int?ActivityID)
        {
            if (ActivityID == null)
            {
                return(NotFound());
            }

            var activity = await _context.Activity.FindAsync(ActivityID);

            if (activity == null)
            {
                return(NotFound());
            }
            var TagsCounter = new List <TagCount>();

            foreach (var tag in _context.Tag)
            {
                var cTag = TagsCounter.SingleOrDefault(e => e.TagName.Equals(tag.TagID));
                if (cTag == null)
                {
                    if (tag.ActivityID.Equals(ActivityID.Value))
                    {
                        TagsCounter.Add(new TagCount {
                            TagName = tag.TagID, TagCounter = 1, IsInActivity = true
                        });
                    }
                    else
                    {
                        TagsCounter.Add(new TagCount {
                            TagName = tag.TagID, TagCounter = 1, IsInActivity = false
                        });
                    }
                }
                else
                {
                    if (tag.ActivityID.Equals(ActivityID.Value))
                    {
                        cTag.TagCounter++;
                        cTag.IsInActivity = true;
                    }
                    else
                    {
                        cTag.TagCounter++;
                    }
                }
            }
            TagsCounter = TagsCounter.OrderByDescending(e => e.IsInActivity == true ? 100000 : 0 + e.TagCounter).ToList();
            var EditActivityViewModel = new EditActivityViewModel
            {
                ActivityID = activity.ActivityID,
                Name       = activity.Name,
                DayOfWeek  = activity.DayOfWeek,
                TimeOfDay  = activity.TimeOfDay,
                Hours      = activity.Hours,
                Importance = activity.Importance,
                Owner      = activity.Owner,
                Tags       = TagsCounter,
            };

            return(View(EditActivityViewModel));
        }
        public ActionResult AddInput(EditActivityViewModel vm)
        {
            try
            {
                if (vm.SelectedActivityInput > 0)
                {
                    /*Models.ActivityInput AI = new ActivityInput();
                     * AI.Activity = DB.Activities.Find(vm.SelectedInputActivity);
                     * AI.InputType = ActivityInput.InputTypeEnum.Number;
                     * AI.OneTime = false;
                     * AI.Required = vm.InputRequired;
                     * AI.Title = vm.InputTitle;
                     * string possibleValues = vm.InputMinValue + ";;" + vm.InputMaxValue;
                     * AI.PossibleValues = possibleValues;
                     * DB.ActivityInputs.Add(AI);
                     * DB.SaveChanges();*/

                    Models.ActivityActivityInput AAI = DB.ActivityActivityInputs.FirstOrDefault(x => x.Activity.ActivityId == vm.SelectedActivity && x.ActivityInput.ActivityInputId == vm.SelectedActivityInput);



                    if (AAI == null)
                    {
                        Models.ActivityActivityInput newAAI = new ActivityActivityInput();

                        Models.Activity      Act = DB.Activities.Find(vm.SelectedActivity);
                        Models.ActivityInput AI  = DB.ActivityInputs.Find(vm.SelectedActivityInput);

                        newAAI.Activity         = Act;
                        newAAI.ActivityInput    = AI;
                        newAAI.Active           = true;
                        newAAI.ActivityInputFor = vm.ActivityInputFor;
                        newAAI.OneTime          = vm.OneTime;
                        newAAI.Required         = vm.Required;

                        DB.ActivityActivityInputs.Add(newAAI);
                    }
                    else
                    {
                        AAI.Active           = true;
                        AAI.ActivityInputFor = vm.ActivityInputFor;
                        AAI.OneTime          = vm.OneTime;
                        AAI.Required         = vm.Required;
                    }

                    DB.SaveChanges();
                }
            }
            catch (Exception e)
            {
                //ERROR
                int x = 10;
            }

            vm.SelectedActivityInput = -1;

            /*vm.InputMaxValue = 10000;
             * vm.InputMinValue = 0;
             * vm.InputRequired = false;
             * vm.InputTitle = "";*/


            return(RedirectToAction("Index", new { activityId = vm.SelectedActivity }));
        }
示例#32
0
        public ActionResult EditActivity(EditActivityViewModel model, int? id)
        {
            var activity = db.Activities.FirstOrDefault(c => c.Id == id);
            Module module = (activity != null ? db.Modules.FirstOrDefault(c => c.Id == activity.ModuleId) : null);
            ViewBag.AtEarliest = (DateTime.Today.AddDays(1) > module.StartDate ? DateTime.Today.AddDays(1) : module.StartDate);
            ViewBag.AtLatest = (DateTime.Today.AddDays(2) < module.EndDate ? module.EndDate : DateTime.Today.AddDays(2));

            Menu(Home: true);
            SetBreadcrumbs(
                one: new MenyItem { Link = "~/Teacher/", Text = "Se alla kurser" },
                three: new MenyItem { Link = "~/Teacher/Activity/" + id, Text = "Tillbaka till aktivitet" });

            if (id == null)
            {
                ViewBag.Error = "Inget id har angivits";
                return View("~/Views/Error/Index.cshtml");
            }

            if (!ModelState.IsValid)
            {
                ViewBag.Id = (int)id;

                return View(model);
            }
            model.StartDate = new DateTime(model.StartDate.Year, model.StartDate.Month, model.StartDate.Day, 0, 0, 0);
            model.EndDate = new DateTime(model.EndDate.Year, model.EndDate.Month, model.EndDate.Day, 23, 59, 0);
            if (model.Deadline != null)
            {
                model.Deadline = new DateTime(((DateTime)model.Deadline).Year, ((DateTime)model.Deadline).Month, ((DateTime)model.Deadline).Day, 23, 59, 0);
            }

            bool hasError = false;
            if (activity == null)
            {
                ModelState.AddModelError("", "Ingen activitet funnen");
                hasError = true;
            }

            if (model.StartDate != null && model.StartDate < DateTime.Today.AddDays(1))
            {
                ModelState.AddModelError("StartDate", "Startdatum kan tyvärr ej starta innan morgondagen, pga. planeringstid");
                hasError = true;
            }
            if (model.EndDate != null && model.StartDate != null && model.EndDate < model.StartDate)
            {
                ModelState.AddModelError("EndDate", "Slutdatumet kan ej vara innan startdatumet");
                hasError = true;
            }
            if (model.EndDate != null && model.EndDate < DateTime.Today.AddDays(1))
            {
                ModelState.AddModelError("EndDate", "Slutdatum kan ej vara innan morgondagen");
                hasError = true;
            }
            if (model.Deadline != null && model.StartDate != null && model.Deadline < model.StartDate)
            {
                ModelState.AddModelError("Deadline", "Deadline för övningsuppgift kan ej vara innan startdatumet");
                hasError = true;
            }
            if (model.Deadline != null && model.EndDate != null && model.Deadline > model.EndDate)
            {
                ModelState.AddModelError("Deadline", "Deadline för övningsuppgift kan ej vara efter slutdatumet");
                hasError = true;
            }
            if (model.Deadline != null && model.Deadline < DateTime.Today.AddDays(1))
            {
                ModelState.AddModelError("Deadline", "Deadline för övningsuppgift kan ej vara innan morgondagen");
                hasError = true;
            }

            if (module == null)
            {
                ModelState.AddModelError("", "Föräldrar modulen kan ej hittas");
                hasError = true;
            }
            else
            {
                if (model.StartDate != null && model.StartDate < module.StartDate)
                {
                    ModelState.AddModelError("StartDate", "Startdatum kan ej starta innan modulen");
                    hasError = true;
                }
                if (model.EndDate != null && model.EndDate > module.EndDate)
                {
                    ModelState.AddModelError("EndDate", "Slutdatum kan ej sluta efter modulen");
                    hasError = true;
                }
                if (model.Deadline != null && model.Deadline < module.StartDate)
                {
                    ModelState.AddModelError("Deadline", "Deadline för övningsuppgift kan ej vara innan modulens startdatum");
                    hasError = true;
                }
                if (model.Deadline != null && model.Deadline > module.EndDate)
                {
                    ModelState.AddModelError("Deadline", "Deadline för övningsuppgift kan ej vara efter modulens slutdatumet");
                    hasError = true;
                }
            }

            if (hasError)
            {
                ViewBag.Id = (int)id;

                return View(model);
            }

            activity.Description = model.Description;
            activity.EndDate = model.EndDate;
            activity.StartDate = model.StartDate;
            activity.Name = model.Name;
            activity.Deadline = model.Deadline;

            db.Entry(activity).State = EntityState.Modified;
            db.SaveChanges();

            return Redirect("~/Teacher/Activity/" + activity.Id);
        }