コード例 #1
0
        // GET: Campaign/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            var currentUser = await _userManager.GetCurrentUser(Context);

            if (currentUser == null)
            {
                return(new HttpUnauthorizedResult());
            }

            if (id == null)
            {
                return(new HttpStatusCodeResult(404));
            }
            Campaign campaign = _dataAccess.GetCampaign((int)id);

            if (!await UserIsTenantAdminOfCampaign(currentUser, campaign))
            {
                return(new HttpUnauthorizedResult());
            }
            if (campaign == null)
            {
                return(new HttpStatusCodeResult(404));
            }

            return(await Task.FromResult(WithTenants(View(campaign))));
        }
コード例 #2
0
        public IActionResult Details(int id)
        {
            var campaign = _dataAccess.GetCampaign(id);

            if (campaign == null)
            {
                HttpNotFound();
            }

            return(View("Details", new CampaignViewModel(campaign)));
        }
コード例 #3
0
        // GET: Campaign/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(404));
            }
            Campaign campaign = _dataAccess.GetCampaign((int)id);

            if (!UserIsTenantAdminOfCampaign(campaign))
            {
                return(new HttpUnauthorizedResult());
            }
            if (campaign == null)
            {
                return(new HttpStatusCodeResult(404));
            }

            return(await Task.FromResult(WithTenants(View(campaign))));
        }
コード例 #4
0
        /// <summary>
        /// Returns null when there is no matching campaign for the campaign Id.
        /// </summary>
        public static Activity ToModel(this ActivityViewModel activity, IAllReadyDataAccess dataAccess)
        {
            var campaign = dataAccess.GetCampaign(activity.CampaignId);

            if (campaign == null)
            {
                return(null);
            }

            Activity newActivity = new Activity()
            {
                Id               = activity.Id,
                Campaign         = campaign,
                EndDateTimeUtc   = activity.EndDateTime.UtcDateTime,
                StartDateTimeUtc = activity.StartDateTime.UtcDateTime,
                Location         = new Location()
                {
                    Address1   = activity.Location.Address1,
                    Address2   = activity.Location.Address2,
                    City       = activity.Location.City,
                    Country    = "US",
                    PostalCode = activity.Location.PostalCode,
                    State      = activity.Location.State
                },
                Name = activity.Title
            };
            var tasks = new List <AllReadyTask>();

            foreach (TaskViewModel tvm in activity.Tasks)
            {
                tasks.Add(new AllReadyTask()
                {
                    Activity    = newActivity,
                    Name        = tvm.Name,
                    Id          = tvm.Id,
                    Description = tvm.Description
                });
            }
            newActivity.Tasks = tasks;
            return(newActivity);
        }
コード例 #5
0
        public void Put(int id, [FromBody] ActivityViewModel value)
        {
            var activity = _allReadyDataAccess.GetActivity(value.Id);

            if (activity == null)
            {
                this.HttpBadRequest();
            }
            var associatedCampaign = _allReadyDataAccess.GetCampaign(value.CampaignId);
            var tenant             = _allReadyDataAccess.GetTenant(value.TenantId);

            // TODO:  Helper method to do this kind of conversion.
            activity.Campaign         = associatedCampaign;
            activity.EndDateTimeUtc   = value.EndDateTime.UtcDateTime;
            activity.Location         = value.Location.ToModel();
            activity.Name             = value.Title;
            activity.StartDateTimeUtc = value.StartDateTime.UtcDateTime;
            activity.Tasks            = value.Tasks.ToModel(_allReadyDataAccess).ToList();
            activity.Tenant           = tenant;

            _allReadyDataAccess.UpdateActivity(activity);
        }
コード例 #6
0
ファイル: ActivityViewModel.cs プロジェクト: fr33k3r/allReady
        /// <summary>
        /// Returns null when there is no matching campaign for the campaign Id.
        /// </summary>
        public static Activity ToModel(this ActivityViewModel activity, IAllReadyDataAccess dataAccess)
        {
            var campaign = dataAccess.GetCampaign(activity.CampaignId);

            if (campaign == null)
                return null;

            Activity newActivity = new Activity()
            {
                Id = activity.Id,
                Campaign = campaign,
                EndDateTimeUtc = activity.EndDateTime.UtcDateTime,
                StartDateTimeUtc = activity.StartDateTime.UtcDateTime,
                Location = new Location()
                {
                    Address1 = activity.Location.Address1,
                    Address2 = activity.Location.Address2,
                    City = activity.Location.City,
                    Country = "US",
                    PostalCode = activity.Location.PostalCode,
                    State = activity.Location.State
                },
                Name = activity.Title
            };
            var tasks = new List<AllReadyTask>();

            foreach (TaskViewModel tvm in activity.Tasks)
            {
                tasks.Add(new AllReadyTask()
                {
                    Activity = newActivity,
                    Name = tvm.Name,
                    Id = tvm.Id,
                    Description = tvm.Description
                });
            }
            newActivity.Tasks = tasks;
            return newActivity;
        }
コード例 #7
0
 public Campaign Handle(CampaignByCampaignIdQuery message)
 {
     return(_dataAccess.GetCampaign(message.CampaignId));
 }