Beispiel #1
0
    public ActionResult Edit(string id, ActivityEditViewModel vm)
    {
        if (ModelState.IsValid == false)
        {
            return(View(vm));
        }

        Activity activity = CompositionRoot.DocumentSession.Load <Activity>(id);

        if (activity == null)
        {
            throw new HttpException(404, "Activity not found");
        }

        Debug.Assert(vm.Season != null, "vm.Season != null");
        Debug.Assert(vm.Date != null, "vm.Date != null");
        activity.Update(
            vm.Season !.Value,
            vm.Title,
            ParseDate(vm.Date !),
            vm.Message,
            vm.MessageHtml,
            User.CustomIdentity.PlayerId !);
        return(RedirectToAction("Index", "ActivityIndex"));
    }
        public async Task <IActionResult> Edit(string workflowsnippetname, string activityId, string returnUrl)
        {
            if (!await _authorizationService.AuthorizeAsync(User, OrchardCore.Workflows.Snippets.Permissions.ManageWorkflowSnippets))
            {
                return(Forbid());
            }

            // var workflowType = await _session.GetAsync<WorkflowType>(workflowTypeId);
            var workflowSnippet = await  GetWorkFlowSnippet(workflowsnippetname);

            var activityRecord  = workflowSnippet.WorkFlowType.Activities.Single(x => x.ActivityId == activityId);
            var activityContext = await _workflowManager.CreateActivityExecutionContextAsync(activityRecord, activityRecord.Properties);

            var activityEditor = await _activityDisplayManager.BuildEditorAsync(activityContext.Activity, _updateModelAccessor.ModelUpdater, isNew : false);

            activityEditor.Metadata.Type = "ActivityWorkflowSnippets_Edit";
            ((dynamic)activityEditor).WorkflowSnippetName = workflowsnippetname;

            var viewModel = new ActivityEditViewModel
            {
                Activity       = activityContext.Activity,
                ActivityId     = activityId,
                ActivityEditor = activityEditor,
                //  WorkflowTypeId = workflowTypeId,
                ReturnUrl = returnUrl
            };

            return(View("EditActivity", viewModel));
        }
        public async Task EditAsyncEditsRestaurantWhenImageStaysTheSame()
        {
            await this.AddTestingDestinationToDb();

            await this.AddTestingActivityToDb();

            await this.DbContext.SaveChangesAsync();

            this.DbContext.Destinations.Add(new Destination {
                Id = SecondTestDestinationId, Name = SecondTestDestinationName
            });
            await this.DbContext.SaveChangesAsync();

            var newName          = SecondTestActivityName;
            var newDestinationId = 2;

            Assert.NotEqual(newName, this.DbContext.Activities.Find(TestActivityId).Name);

            var activityEditViewModel = new ActivityEditViewModel()
            {
                Id            = TestActivityId,
                Name          = newName,
                DestinationId = newDestinationId,
                Type          = TestActivityType,
                NewImage      = null,
            };

            await this.ActivitiesServiceMock.EditAsync(activityEditViewModel);

            Assert.Equal(newName, this.DbContext.Activities.Find(TestActivityId).Name);
        }
        public async Task <IActionResult> Edit(int workflowTypeId, string activityId, string returnUrl)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows))
            {
                return(Forbid());
            }

            var workflowType = await _session.GetAsync <WorkflowType>(workflowTypeId);

            var activityRecord  = workflowType.Activities.Single(x => x.ActivityId == activityId);
            var activityContext = await _workflowManager.CreateActivityExecutionContextAsync(activityRecord, activityRecord.Properties);

            var activityEditor = await _activityDisplayManager.BuildEditorAsync(activityContext.Activity, _updateModelAccessor.ModelUpdater, isNew : false);

            activityEditor.Metadata.Type = "Activity_Edit";

            var viewModel = new ActivityEditViewModel
            {
                Activity       = activityContext.Activity,
                ActivityId     = activityId,
                ActivityEditor = activityEditor,
                WorkflowTypeId = workflowTypeId,
                ReturnUrl      = returnUrl
            };

            return(View("EditActivity", viewModel));
        }
        public async Task <IActionResult> Edit(ActivityEditViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows))
            {
                return(Forbid());
            }

            var workflowType = await _session.GetAsync <WorkflowType>(model.WorkflowTypeId);

            var activityRecord  = workflowType.Activities.Single(x => x.ActivityId == model.ActivityId);
            var activityContext = await _workflowManager.CreateActivityExecutionContextAsync(activityRecord, activityRecord.Properties);

            var activityEditor = await _activityDisplayManager.UpdateEditorAsync(activityContext.Activity, _updateModelAccessor.ModelUpdater, isNew : false);

            if (!ModelState.IsValid)
            {
                activityEditor.Metadata.Type = "Activity_Edit";
                model.Activity       = activityContext.Activity;
                model.ActivityEditor = activityEditor;

                return(View("EditActivity", model));
            }

            activityRecord.Properties = activityContext.Activity.Properties;

            _session.Save(workflowType);
            _notifier.Success(H["Activity updated successfully."]);

            return(Url.IsLocalUrl(model.ReturnUrl)
                ? (IActionResult)Redirect(model.ReturnUrl)
                : RedirectToAction("Edit", "WorkflowType", new { id = model.WorkflowTypeId }));
        }
        public async Task <IActionResult> Create(string activityName, int workflowTypeId, string returnUrl)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows))
            {
                return(Forbid());
            }

            var activity       = _activityLibrary.InstantiateActivity(activityName);
            var activityId     = _activityIdGenerator.GenerateUniqueId(new ActivityRecord());
            var activityEditor = await _activityDisplayManager.BuildEditorAsync(activity, _updateModelAccessor.ModelUpdater, isNew : true);

            activityEditor.Metadata.Type = "Activity_Edit";

            var viewModel = new ActivityEditViewModel
            {
                Activity       = activity,
                ActivityId     = activityId,
                ActivityEditor = activityEditor,
                WorkflowTypeId = workflowTypeId,
                ReturnUrl      = returnUrl
            };

            if (!activity.HasEditor)
            {
                // No editor to show; short-circuit to the "POST" action.
                return(await Create(activityName, viewModel));
            }

            return(View(viewModel));
        }
        public async Task <IActionResult> Create(string activityName, ActivityEditViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageWorkflows))
            {
                return(Forbid());
            }

            var workflowType = await _session.GetAsync <WorkflowType>(model.WorkflowTypeId);

            var activity       = _activityLibrary.InstantiateActivity(activityName);
            var activityEditor = await _activityDisplayManager.UpdateEditorAsync(activity, _updateModelAccessor.ModelUpdater, isNew : true);

            if (!ModelState.IsValid)
            {
                activityEditor.Metadata.Type = "Activity_Edit";
                model.Activity       = activity;
                model.ActivityEditor = activityEditor;
                return(View(model));
            }

            var activityRecord = new ActivityRecord
            {
                ActivityId = model.ActivityId,
                Name       = activity.Name,
                Properties = activity.Properties,
            };

            workflowType.Activities.Add(activityRecord);

            _session.Save(workflowType);
            _notifier.Success(H["Activity added successfully."]);

            return(Url.IsLocalUrl(model.ReturnUrl) ? (IActionResult)Redirect(model.ReturnUrl) : RedirectToAction("Edit", "WorkflowType", new { id = model.WorkflowTypeId }));
        }
Beispiel #8
0
    public ActionResult Create(int?season)
    {
        if (season.HasValue == false)
        {
            season = CompositionRoot.DocumentSession.LatestSeasonOrDefault(SystemTime.UtcNow.Year);
        }

        return(View(ActivityEditViewModel.ForCreate(season.Value)));
    }
Beispiel #9
0
    public ActionResult Edit(string id)
    {
        Activity activity = CompositionRoot.DocumentSession.Load <Activity>(id);

        if (activity == null)
        {
            throw new HttpException(404, "Activity not found");
        }

        return(View(ActivityEditViewModel.ForEdit(activity)));
    }
Beispiel #10
0
        public ActionResult Edit(int?id, int?page)
        {
            //記錄目前頁數,若是空值就給1
            TempData["savepage"] = page ?? 1;

            var av = db.Activities.Find(id ?? 1);

            ActivityEditViewModel        aevm   = new ActivityEditViewModel();
            List <ActivityProdViewModel> apList = new List <ActivityProdViewModel>();

            aevm.ActivityID   = av.ActivityID;
            aevm.ActivityName = av.ActivityName;
            aevm.BeginDate    = av.BeginDate;
            aevm.EndDate      = av.EndDate;
            aevm.DiscountID   = av.DiscountID;
            aevm.DiscountName = db.DiscountMethods.Find(av.DiscountID).DiscountName;
            aevm.CreateDate   = av.CreateDate;
            aevm.PhotoID      = av.PhotoID;

            var                     ap        = db.ActivityProducts.Where(x => x.ActivityID == id);
            List <Product>          prod      = db.Products.ToList();
            List <VW_EW_CategorySM> cateMS    = db.VW_EW_CategorySM.ToList();
            List <Supplier>         suppliers = db.Suppliers.ToList();
            List <ProductPhoto>     prodPhoto = db.ProductPhotoes.ToList();


            foreach (var item in ap)
            {
                ActivityProdViewModel apvm = new ActivityProdViewModel();

                apvm.ActivityID = item.ActivityID;
                apvm.ProductID  = item.ProductID;
                var pd = prod.Where(x => x.ProductID == item.ProductID).FirstOrDefault();
                apvm.ProductName    = pd.ProductName;
                apvm.CategoryMSName = cateMS.Where(x => x.CategorySID == pd.CategorySID).FirstOrDefault().CategoryName;
                apvm.SupplierName   = suppliers.Where(x => x.SupplierID == pd.SupplierID).FirstOrDefault().SupplierName;

                if (prodPhoto.Any(x => x.ProductID == item.ProductID && ((x.PhotoID == null ? 0 : x.PhotoID) > 0)))
                {
                    apvm.PhotoID = (int)prodPhoto.Where(x => x.ProductID == item.ProductID).FirstOrDefault().PhotoID;
                }
                //aevm.producstList
                apList.Add(apvm);
            }

            aevm.producstList = apList;

            ViewBag.datas = db.DiscountMethods;
            return(View(aevm));
        }
Beispiel #11
0
        public async Task <IActionResult> Edit(ActivityEditViewModel input)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView("_ActivityEditPartial", input));
            }
            var activityToEdit = input.To <ActivityEditDto>();

            await this.activitiesService.EditActivityAsync(activityToEdit);

            var redirectUrl = Url.Action("Details", "Reports", new { id = input.ReportId });

            return(Json(new { success = true, url = redirectUrl }));
        }
        public async Task <IActionResult> Edit(ActivityEditViewModel activityToEditViewModel)
        {
            if (activityToEditViewModel.NewImage != null)
            {
                var fileType = activityToEditViewModel.NewImage.ContentType.Split('/')[1];
                if (!this.IsImageTypeValid(fileType))
                {
                    return(this.View(activityToEditViewModel));
                }
            }

            await this.activitiesService.EditAsync(activityToEditViewModel);

            return(this.RedirectToAction("Details", "Activities", new { area = "", id = activityToEditViewModel.Id }));
        }
        public async Task <IActionResult> Edit(int id, ActivityEditViewModel activity)
        {
            if (id != activity.Id)
            {
                return(NotFound());
            }

            if (activity.EndDate < activity.StartDate)
            {
                ModelState.AddModelError("EndDate", "Sluttiden kan inte vara tidigare än starttiden");
            }

            /* var found = await _context.Courses.AnyAsync(p => (p.Name == activity.Name) && (p.Id != activity.Id));
             * if (found)
             * {
             *   ModelState.AddModelError("Name", "Det finns redan en kurs med denna namn");
             * }*/

            var model = mapper.Map <Activity>(activity);

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(model);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ActivityExists(model.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                TempData["SuccessText"] = $"Aktivitet: {activity.Name} - är uppdaterad!";
                //return RedirectToAction(nameof(Index));
                var CourseId = _context.Modules.Where(m => m.Id == model.ModuleId).Select(m => m.CourseId).FirstOrDefault();
                return(RedirectToAction(nameof(Details), "Courses", new { id = CourseId }));
            }

            TempData["FailText"] = $"Något gick fel! Aktivitet: {activity.Name} - är inte uppdaterad!";

            return(View(activity));
        }
        public async Task EditAsyncThrowsArgumentExceptionIfActivityTypeInvalid()
        {
            await this.AddTestingDestinationToDb();

            var invalidActivityEditInputModel = new ActivityEditViewModel()
            {
                Name          = TestActivityName,
                DestinationId = TestDestinationId,
                Type          = InvalidActivityType,
            };

            var exception = await Assert.ThrowsAsync <ArgumentException>(() =>
                                                                         this.ActivitiesServiceMock.EditAsync(invalidActivityEditInputModel));

            Assert.Equal(string.Format(ServicesDataConstants.InvalidActivityType, invalidActivityEditInputModel.Type), exception.Message);
        }
        public async Task EditAsyncThrowsNullReferenceExceptionIfDestinationNotFound()
        {
            await this.AddTestingActivityToDb();

            var invalidActivityEditViewModel = new ActivityEditViewModel()
            {
                Id            = TestActivityId,
                Name          = TestActivityName,
                DestinationId = TestDestinationId,
                Type          = TestActivityType,
            };

            var exception = await Assert.ThrowsAsync <NullReferenceException>(() =>
                                                                              this.ActivitiesServiceMock.EditAsync(invalidActivityEditViewModel));

            Assert.Equal(string.Format(ServicesDataConstants.NullReferenceDestinationId, invalidActivityEditViewModel.DestinationId), exception.Message);
        }
Beispiel #16
0
        public ActionResult Edit([Bind(Include = "Id,Name,Description,StartDate,EndDate,TypeId,ModuleId")] Activity activity)
        {
            if (ModelState.IsValid)
            {
                var module = db.Modules.FirstOrDefault(m => m.Id == activity.ModuleId);
                if (Util.Validation.DateRangeValidation(this, module, activity))
                {
                    db.Entry(activity).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Index", "CourseDetails", new { id = module.CourseId }));
                }
                activity.Module = module;
            }
            ActivityEditViewModel model = Mapper.Map <Activity, ActivityEditViewModel>(activity);

            //model.SelectModule = new SelectList(db.Modules, "Id", "Name", activity.ModuleId);
            model.SelectType = new SelectList(db.ActivityTypes, "Id", "Description", activity.TypeId);
            return(View(model));
        }
Beispiel #17
0
        public ActionResult Create(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Module module = db.Modules.Find(id?.Decode());

            if (module == null)
            {
                return(HttpNotFound());
            }
            ActivityEditViewModel aevm = new ActivityEditViewModel();

            Session["moduleid"]  = module.Id;
            aevm.Types           = db.ActivityTypes.ToList();
            aevm.ModuleStartDate = module.StartDate.ToString("yyyy-MM-dd");
            aevm.ModuleEndDate   = module.EndDate.ToString("yyyy-MM-dd");
            return(PartialView("_Create", aevm));
        }
        public async Task EditAsync(ActivityEditViewModel activityToEditViewModel)
        {
            if (!Enum.TryParse(activityToEditViewModel.Type, true, out ActivityType activityTypeEnum))
            {
                throw new ArgumentException(string.Format(ServicesDataConstants.InvalidActivityType, activityToEditViewModel.Type));
            }

            var activity = await this.activitiesRepository.All().FirstOrDefaultAsync(a => a.Id == activityToEditViewModel.Id);

            if (activity == null)
            {
                throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceActivityId, activityToEditViewModel.Id));
            }

            var destination = await this.destinationsRepository.All().FirstOrDefaultAsync(l => l.Id == activityToEditViewModel.DestinationId);

            if (destination == null)
            {
                throw new NullReferenceException(string.Format(ServicesDataConstants.NullReferenceDestinationId, activityToEditViewModel.DestinationId));
            }

            if (activityToEditViewModel.NewImage != null)
            {
                var newImageUrl = await ApplicationCloudinary.UploadImage(this.cloudinary, activityToEditViewModel.NewImage, activityToEditViewModel.Name);

                activity.ImageUrl = newImageUrl;
            }

            activity.Name           = activityToEditViewModel.Name;
            activity.Type           = activityTypeEnum;
            activity.Date           = activityToEditViewModel.Date;
            activity.Description    = activityToEditViewModel.Description;
            activity.AdditionalInfo = activityToEditViewModel.AdditionalInfo;
            activity.Destination    = destination;
            activity.Address        = activityToEditViewModel.Address;
            activity.LocationName   = activityToEditViewModel.LocationName;
            activity.Price          = activityToEditViewModel.Price;

            this.activitiesRepository.Update(activity);
            await this.activitiesRepository.SaveChangesAsync();
        }
Beispiel #19
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Activity activity = db.Activities.Find(id?.Decode());

            if (activity == null)
            {
                return(HttpNotFound());
            }
            ActivityEditViewModel aevm = activity;

            Session["activityid"] = activity.Id;
            aevm.Types            = db.ActivityTypes.ToList();
            aevm.ModuleStartDate  = activity.Module.StartDate.ToString("yyyy-MM-dd");
            aevm.ModuleEndDate    = activity.Module.EndDate.ToString("yyyy-MM-dd");
            return(PartialView("_Edit", aevm));
        }
Beispiel #20
0
        public async Task <IActionResult> Edit(Guid id, ActivityEditViewModel model)
        {
            if (id != model.Id)
            {
                return(NotFound());
            }

            if (model.EndTime <= model.BeginTime)
            {
                ModelState.AddModelError(string.Empty, "End Time can't be earlier than Begin Time!");
            }

            if (await _activityService.ExistsAsync(model.Id, model.Name))
            {
                ModelState.AddModelError(string.Empty, "Another activity has the same name!");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var updatedBy = User.GetUsername();
                    await _activityService.UpdateAsync(model.Id, model.Name, model.BeginTime, model.EndTime, model.Description, updatedBy);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await _activityService.ExistsAsync(id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Beispiel #21
0
    public ActionResult Create(ActivityEditViewModel vm)
    {
        if (ModelState.IsValid == false)
        {
            return(View(vm));
        }

        Debug.Assert(vm.Season != null, "vm.Season != null");
        Debug.Assert(vm.Date != null, "vm.Date != null");
        Activity activity =
            Activity.Create(
                vm.Season !.Value,
                vm.Title,
                ParseDate(vm.Date !),
                vm.Message,
                vm.MessageHtml,
                User.CustomIdentity.PlayerId !);

        CompositionRoot.DocumentSession.Store(activity);

        return(RedirectToAction("Index", "ActivityIndex"));
    }
Beispiel #22
0
        public ActionResult Edit(ActivityEditViewModel aevm)
        {
            int?id = (int?)HttpContext.Session["activityid"];

            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Activity updatedActivity = null;

            if (ModelState.IsValid)
            {
                updatedActivity = db.Activities.Find(id);
                if (updatedActivity != null && TryUpdateModel(updatedActivity, "", new string[] { "Name", "Description", "StartTime", "EndTime" }))
                {
                    try
                    {
                        updatedActivity.TypeId    = aevm.Type;
                        updatedActivity.StartTime = aevm.StartDate.Date + updatedActivity.StartTime.TimeOfDay;
                        updatedActivity.EndTime   = aevm.EndDate.Date + updatedActivity.EndTime.TimeOfDay;
                        db.SaveChanges();
                        aevm = updatedActivity;                         // ActivityEditViewModel
                        TempData["alert"] = "success|Aktiviteten är uppdaterad!|a" + updatedActivity.Id.Encode();
                    }
                    catch (RetryLimitExceededException)
                    {
                        ModelState.AddModelError("", "Kan inte spara ändringar. Försök igen och om problemet kvarstår kontakta din systemadministratör.");
                        TempData["alert"] = "danger|Allvarligt fel!";
                    }
                }
                else
                {
                    TempData["alert"] = "danger|Kunde inte uppdatera aktiviteten!";
                }
            }
            aevm.Types = db.ActivityTypes.ToList();
            return(PartialView("_Edit", aevm));
        }
        public async Task EditAsyncEditsRestaurantsImage()
        {
            await this.AddTestingDestinationToDb();

            this.DbContext.Activities.Add(new Activity
            {
                Id            = TestActivityId,
                Name          = TestActivityName,
                DestinationId = TestDestinationId,
                Type          = ActivityType.Adventure,
                ImageUrl      = TestImageUrl,
            });
            await this.DbContext.SaveChangesAsync();

            using (var stream = File.OpenRead(TestImagePath))
            {
                var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
                {
                    Headers     = new HeaderDictionary(),
                    ContentType = TestImageContentType,
                };

                var activityToEditViewModel = new ActivityEditViewModel()
                {
                    Id            = TestActivityId,
                    Name          = TestActivityName,
                    DestinationId = TestDestinationId,
                    Type          = TestActivityType,
                    NewImage      = file,
                };

                await this.ActivitiesServiceMock.EditAsync(activityToEditViewModel);

                ApplicationCloudinary.DeleteImage(ServiceProvider.GetRequiredService <Cloudinary>(), activityToEditViewModel.Name);
            }

            Assert.NotEqual(TestImageUrl, this.DbContext.Activities.Find(TestActivityId).ImageUrl);
        }
Beispiel #24
0
        // GET: Activities/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Activity activity = db.Activities.Find(id);

            if (activity == null)
            {
                return(HttpNotFound());
            }

            ActivityEditViewModel model = Mapper.Map <Activity, ActivityEditViewModel>(activity);
            var module = db.Modules.FirstOrDefault(m => m.Id == activity.ModuleId);

            model.CourseId = module.CourseId;

            //model.ModuleId = activity.ModuleId;
            //model.SelectModule = new SelectList(db.Modules, "Id", "Name", activity.ModuleId);
            model.SelectType = new SelectList(db.ActivityTypes, "Id", "Description", activity.TypeId);
            return(View(model));
        }
        public async Task <IActionResult> Create(string activityName, ActivityEditViewModel model, string workflowsnippetname)
        {
            if (!await _authorizationService.AuthorizeAsync(User, OrchardCore.Workflows.Snippets.Permissions.ManageWorkflowSnippets))
            {
                return(Forbid());
            }

            // var workflowType = await _session.GetAsync<WorkflowType>(model.WorkflowTypeId);
            var workflowSnippet = await  GetWorkFlowSnippet(workflowsnippetname);

            var activity       = _activityLibrary.InstantiateActivity(activityName);
            var activityEditor = await _activityDisplayManager.UpdateEditorAsync(activity, _updateModelAccessor.ModelUpdater, isNew : true);

            if (!ModelState.IsValid)
            {
                activityEditor.Metadata.Type = "ActivityWorkflowSnippets_Edit";
                ((dynamic)activityEditor).WorkflowSnippetName = workflowsnippetname;
                model.Activity       = activity;
                model.ActivityEditor = activityEditor;
                return(View(model));
            }

            var activityRecord = new ActivityRecord
            {
                ActivityId = model.ActivityId,
                Name       = activity.Name,
                Properties = activity.Properties,
            };

            workflowSnippet.WorkFlowType.Activities.Add(activityRecord);
            await UpdateWorkFlowSnippet(workflowsnippetname, workflowSnippet);

            //  _session.Save(workflowType);
            _notifier.Success(H["Activity added successfully"]);

            return(Url.IsLocalUrl(model.ReturnUrl) ? (IActionResult)Redirect(model.ReturnUrl) : RedirectToAction("Edit", "WorkflowSnippetsAdmin", new { sourcename = workflowsnippetname }));
        }
Beispiel #26
0
        public ActionResult Create(ActivityEditViewModel aevm)
        {
            string returnView = "_Create";

            try
            {
                if (ModelState.IsValid)
                {
                    Activity newActivity = new Activity();
                    if (TryUpdateModel(newActivity, "", new string[] { "Name", "Description", "StartTime", "EndTime" }))
                    {
                        newActivity.ModuleId  = (int)Session["moduleid"];
                        newActivity.TypeId    = aevm.Type;
                        newActivity.StartTime = aevm.StartDate.Date + newActivity.StartTime.TimeOfDay;
                        newActivity.EndTime   = aevm.EndDate.Date + newActivity.EndTime.TimeOfDay;
                        db.Activities.Add(newActivity);
                        db.SaveChanges();
                        aevm = newActivity;                         // ActivityEditViewModel
                        Session["activityid"] = newActivity.Id;
                        TempData["alert"]     = "success|Aktiviteten är tillagd!|a" + newActivity.Id.Encode();
                        returnView            = "_Edit";
                    }
                    else
                    {
                        TempData["alert"] = "danger|Kunde inte lägga till aktivitet";
                    }
                }
            }
            catch (DataException)
            {
                ModelState.AddModelError("", "Kan inte spara ändringar. Försök igen och om problemet kvarstår kontakta din systemadministratör.");
                TempData["alert"] = "danger|Allvarligt fel!";
            }
            aevm.Types = db.ActivityTypes.ToList();
            return(PartialView(returnView, aevm));
        }
Beispiel #27
0
        public IActionResult Edit(Activity activity)
        {
            if (!ModelState.IsValid)
            {
                ActivityEditViewModel activityEditViewModel = new ActivityEditViewModel();
                activityEditViewModel.Priorities = htmlHelper.GetEnumSelectList <Priority>();
                activityEditViewModel.Activity   = activity;
                return(View(activityEditViewModel));
            }

            if (activity.Id > 0)
            {
                activityRepository.Update(activity);
                TempData["Message"] = $"Zadanie '{activity.Title}' zostało zapisane.";
            }
            else
            {
                activityRepository.Add(activity);
                TempData["Message"] = $"Zadanie '{activity.Title}' zostało utworzone.";
            }

            activityRepository.Commit();
            return(RedirectToAction("Index"));
        }
Beispiel #28
0
        public IActionResult Edit(int?activityId)
        {
            ActivityEditViewModel activityEditViewModel = new ActivityEditViewModel();

            activityEditViewModel.Priorities = htmlHelper.GetEnumSelectList <Priority>();

            if (activityId.HasValue)
            {
                activityEditViewModel.Activity = activityRepository.Get(activityId.Value);
                if (activityEditViewModel.Activity != null)
                {
                    return(View(activityEditViewModel));
                }
                else
                {
                    return(RedirectToAction("NotFound"));
                }
            }
            else
            {
                activityEditViewModel.Activity = new Activity();
                return(View(activityEditViewModel));
            }
        }
        public async Task <IActionResult> Edit(ActivityEditViewModel model, string workflowsnippetname)
        {
            if (!await _authorizationService.AuthorizeAsync(User, OrchardCore.Workflows.Snippets.Permissions.ManageWorkflowSnippets))
            {
                return(Forbid());
            }

            //  var workflowType = await _session.GetAsync<WorkflowType>(model.WorkflowTypeId);
            var workflowSnippet = await  GetWorkFlowSnippet(workflowsnippetname);

            var activityRecord  = workflowSnippet.WorkFlowType.Activities.Single(x => x.ActivityId == model.ActivityId);
            var activityContext = await _workflowManager.CreateActivityExecutionContextAsync(activityRecord, activityRecord.Properties);

            var activityEditor = await _activityDisplayManager.UpdateEditorAsync(activityContext.Activity, _updateModelAccessor.ModelUpdater, isNew : false);

            if (!ModelState.IsValid)
            {
                activityEditor.Metadata.Type = "ActivityWorkflowSnippets_Edit";
                ((dynamic)activityEditor).WorkflowSnippetName = workflowsnippetname;
                model.Activity       = activityContext.Activity;
                model.ActivityEditor = activityEditor;

                return(View("EditActivity", model));
            }

            activityRecord.Properties = activityContext.Activity.Properties;

            await UpdateWorkFlowSnippet(workflowsnippetname, workflowSnippet);

            //  _session.Save(workflowType);
            _notifier.Success(H["Activity updated successfully"]);

            return(Url.IsLocalUrl(model.ReturnUrl)
                ? (IActionResult)Redirect(model.ReturnUrl)
                : RedirectToAction("Edit", "WorkflowSnippetsAdmin", new { sourcename = workflowsnippetname }));
        }
        // GET: Activities/Edit/5
        public async Task <IActionResult> ActivityEdit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var activity = await _context.Activities.FindAsync(id);

            if (activity == null)
            {
                return(NotFound());
            }

            var viewModel = new ActivityEditViewModel()
            {
                ActivityId  = activity.ActivityId,
                Name        = activity.Name,
                Description = activity.Description
            };

            viewModel.ActivityTimeInvitees = await _context.ActivityTimeInvitees
                                             .Where(ati => ati.ActivityId == viewModel.ActivityId)
                                             .Select(ati => new ActivityTimeInvitee()
            {
                TimeProposedId = ati.TimeProposedId,
                InviteeId      = ati.InviteeId
            }).ToListAsync();

            var inviteeKeys = viewModel.ActivityTimeInvitees
                              .Where(ati => ati.InviteeId != null)
                              .Select(ati => (int)ati.InviteeId)
                              .Distinct()
                              .ToList();

            Invitee tempInvitee;

            foreach (int key in inviteeKeys)
            {
                tempInvitee = _context.Invitees
                              .FirstOrDefault(i => i.InviteeId == key);
                viewModel.Invitees.Add(new Invitee()
                {
                    InviteeId = tempInvitee.InviteeId,
                    Name      = tempInvitee.Name
                });
            }

            var timeKeys = viewModel.ActivityTimeInvitees
                           .Where(ati => ati.TimeProposedId != null)
                           .Select(ati => (int)ati.TimeProposedId)
                           .Distinct()
                           .ToList();

            TimeProposed tempTimeProposed;

            foreach (int key in timeKeys)
            {
                tempTimeProposed = _context.TimeProposeds
                                   .FirstOrDefault(tp => tp.TimeProposedId == key);
                viewModel.TimeProposeds.Add(new TimeProposed()
                {
                    TimeProposedId = tempTimeProposed.TimeProposedId,
                    StartTime      = tempTimeProposed.StartTime,
                    EndTime        = tempTimeProposed.EndTime
                });
            }

            return(View(viewModel));
        }