Ejemplo n.º 1
0
        public async Task <IActionResult> Post(int personId, [FromBody] EventViewModel eventViewModel)
        {
            if (ModelState.IsValid)
            {
                var newEvent = Mapper.Map <Event>(eventViewModel);
                if (eventViewModel.Place?.Id == null)
                {
                    newEvent.Place = null;
                }
                if (await _eventService.Add(personId, newEvent))
                {
                    return(Created($"api/events/{eventViewModel.Name}", Mapper.Map <EventViewModel>(newEvent)));
                }

                _logger.LogError("Failed to save event to database");
            }
            else
            {
                var errorMessage = string.Join(" | ", ModelState.Values
                                               .SelectMany(v => v.Errors)
                                               .Select(e => e.ErrorMessage));
                _logger.LogError($"Model not valid ({errorMessage})");
            }

            return(BadRequest("Failed to save event"));
        }
Ejemplo n.º 2
0
        public ActionResult Create(EventSchedulerViewModel evm)
        {
            Event e = new Event();

            e.Title        = evm.EventModel.Title;
            e.Address      = evm.EventModel.Address;
            e.NumberPlaces = evm.EventModel.NumberPlaces;
            e.Price        = evm.EventModel.Price;
            e.Description  = evm.EventModel.Description;
            e.Start        = evm.EventModel.Start;
            e.End          = evm.EventModel.End;
            e.OrganizedBy  = evm.EventModel.OrganizedBy;
            eventService.Add(e);
            eventService.Commit();

            foreach (Scheduler scheduler in listScheduler)
            {
                Scheduler s = new Scheduler()
                {
                    Duration = scheduler.Duration, ProgramName = scheduler.ProgramName, EventId = e.EventId
                };
                schedulerService.Add(s);
                schedulerService.Commit();
            }
            try
            {
                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 3
0
        public void AddShould_ReturnNewEventObject_WithExpectedProperties()
        {
            // Arrange
            var eventRepoMock = new Mock <IEventRepository>();
            var eventObj      = new Event()
            {
                Id        = 1,
                StartDate = DateTime.Now
            };

            eventRepoMock.Setup(x => x.Add(It.IsAny <Event>())).Returns(
                eventObj
                );

            var service = new EventService(eventRepoMock.Object);

            // Act
            var result = service.Add();

            // Assert
            Assert.AreEqual(eventObj.Id, result.Id);
            Assert.AreEqual(eventObj.StartDate, result.StartDate);
            Assert.AreEqual(eventObj.Name, null);
            Assert.AreEqual(eventObj.OddsForFirstTeam, null);
            Assert.AreEqual(eventObj.OddsForDraw, null);
            Assert.AreEqual(eventObj.OddsForSecondTeam, null);
        }
Ejemplo n.º 4
0
 public void Add()
 {
     if (IsEdit == true)
     {
         toEdit.Name        = Name;
         toEdit.Description = Description;
         if (SelectedUser != null)
         {
             toEdit.UserId = SelectedUser.Id;
         }
         toEdit.OrderId  = SelectedOrder.Id;
         toEdit.Executed = Executed;
         EventService.Edit(toEdit);
     }
     else
     {
         var newEvent = new EventDTO();
         newEvent.Name        = Name;
         newEvent.Description = Description;
         if (SelectedUser != null)
         {
             newEvent.UserId = SelectedUser.Id;
         }
         newEvent.OrderId  = SelectedOrder.Id;
         newEvent.Executed = Executed;
         EventService.Add(newEvent);
     }
     TryClose();
 }
Ejemplo n.º 5
0
        public ActionResult Create(EventViewModel EVM)
        {
            EventIservice   EVS         = new EventService();
            int             userconnect = Int32.Parse(User.Identity.GetUserId());
            int             a           = 0;
            var             events      = EVS.eventGetAll(userconnect);
            List <DateTime> d           = new List <DateTime>();

            foreach (var item in events)
            {
                d.Add(item.Start);
            }
            if (d.Contains(EVM.Start) == false)
            {
                if ((EVM.Start > DateTime.Now) || (EVM.Start > EVM.End))
                {
                    Event Ev = new Event();
                    Ev.Description = EVM.Description;
                    Ev.IsFullDay   = 0;
                    Ev.DoctorId    = userconnect;
                    Ev.Start       = EVM.Start;
                    Ev.End         = EVM.End;
                    Ev.ThemeColor  = "red";
                    Ev.Subject     = EVM.Subject;
                    EVS.Add(Ev);
                    EVS.Commit();
                }
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        public void AddShould_CallRepositoryAddMethod_Once()
        {
            // Arrange
            var eventRepoMock = new Mock <IEventRepository>();

            eventRepoMock.Setup(x => x.Add(It.IsAny <Event>())).Returns(
                new Event()
            {
                Id                = 1,
                Name              = "Test",
                OddsForFirstTeam  = 1,
                OddsForDraw       = 2,
                OddsForSecondTeam = 3,
                StartDate         = DateTime.Now
            }
                );

            var service = new EventService(eventRepoMock.Object);

            // Act
            var result = service.Add();

            // Assert
            eventRepoMock.Verify(x => x.Add(It.IsAny <Event>()), Times.Once);
        }
Ejemplo n.º 7
0
        public void Add(EventLR e)
        {
            var model = EventService.Add();

            model.Item = e;
            Add(model);
        }
Ejemplo n.º 8
0
        public IHttpActionResult Post([FromBody] EventDTO newEvent)
        {
            if (!ModelState.IsValid)
            {
                return(Json(ModelState.Errors(), BOT_SERIALIZER_SETTINGS));
            }
            var addedEvent = service.Add(newEvent);

            return(Json(addedEvent, BOT_SERIALIZER_SETTINGS));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("Id,Name,Location,StartDateTime,EndDateTime")] Event @event)
        {
            if (ModelState.IsValid)
            {
                events.Add(@event);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@event));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Create(EventsDetailViewModel model)
        {
            if (model.UseLocation && !model.Event.AtLocationId.HasValue)
            {
                ModelState.AddModelError("Event.AtLocationId", "The At Location field is required.");
            }
            if (!model.UseLocation && !model.Event.AtBranchId.HasValue)
            {
                ModelState.AddModelError("Event.AtBranchId", "The At Branch field is required.");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(model.Event.ExternalLink))
                    {
                        model.Event.ExternalLink = new UriBuilder(
                            model.Event.ExternalLink).Uri.AbsoluteUri;
                    }
                    var graEvent = model.Event;
                    if (model.UseLocation)
                    {
                        graEvent.AtBranchId = null;
                    }
                    else
                    {
                        graEvent.AtLocationId = null;
                    }
                    graEvent.IsActive = true;
                    graEvent.IsValid  = true;

                    await _eventService.Add(graEvent);

                    ShowAlertSuccess($"Event '{graEvent.Name}' created.");
                    return(RedirectToAction("Index"));
                }
                catch (GraException gex)
                {
                    ShowAlertWarning("Could not create event: ", gex.Message);
                }
            }
            PageTitle = "Create Event";

            var branchList = await _siteService.GetBranches(GetId(ClaimType.SystemId));

            var locationList = await _eventService.GetLocations();

            var programList = await _siteService.GetProgramList();

            model.BranchList   = new SelectList(branchList, "Id", "Name");
            model.LocationList = new SelectList(locationList, "Id", "Name");
            model.ProgramList  = new SelectList(programList, "Id", "Name");
            return(View(model));
        }
Ejemplo n.º 11
0
        public ActionResult Create(evenement E)
        {
            try
            {
                ES.Add(E);
                ES.Commit();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 12
0
        public IActionResult Post([FromBody] EventBatchRequestDto batch)
        {
            if (networkService.IsSimulatingNetworkFailure)
            {
                networkService.IsSimulatingNetworkFailure = false;
                return(new NotFoundResult());
            }

            var events = batch.Events.Select(FromDto);

            eventService.Add(events);

            return(new OkResult());
        }
Ejemplo n.º 13
0
 public void UserEventLogging(AppUser user, string eventDesc, int eventTypeId)
 {
     try
     {
         using (EventService eventService = new EventService())
         {
             Event eventModel = new Event();
             eventModel.EventTypeId      = eventTypeId;
             eventModel.SubscriberId     = user.Subscriber_Id ?? 0;
             eventModel.EventDescription = eventDesc;
             eventModel.CreatedOn        = DateTime.Now;
             eventModel.CreatedBy        = user.UserName;
             eventService.Add(eventModel);
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Error Logging User Events " + Environment.NewLine + ex.Message);
     }
 }
Ejemplo n.º 14
0
        public ActionResult Create(int Id, AppointmentViewModel collection)
        {
            Appointment a = new Appointment();



            //  appdate=collection.AppDate+collection.app
            a.AppDate = collection.AppDate;



            a.AppointmentId = collection.AppointmentId;
            a.AppRate       = collection.AppRate;
            a.VisitReason   = collection.VisitReason;
            //  a.DoctorId = collection.DoctorId;
            a.DoctorId  = Id;
            a.PatientId = int.Parse(User.Identity.GetUserId());


            Event e = new Event();

            e.Subject     = us.GetUserById(a.PatientId).FirstName + " " + us.GetUserById(a.PatientId).LastName;
            e.Description = collection.VisitReason;
            e.Start       = collection.AppDate;
            TimeSpan tspan = new TimeSpan(0, 0, 15, 0);

            e.End        = collection.AppDate + tspan;
            e.ThemeColor = "green";
            e.DoctorId   = Id;

            EventService SV = new EventService();

            SV.Add(e);
            SV.Commit();

            AS.Add(a);
            AS.Commit();

            DateTime today = DateTime.Today;
            TimeSpan gap   = collection.AppDate - today;


            /****Mail****/
            // if (gap < 24)
            {
                try
                {
                    MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**", "RENDEZ-VOUS", "vous avez un rdv le ");
                    message.IsBodyHtml = true;
                    SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                    client.EnableSsl   = true;
                    client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "motdepasse");
                    client.Send(message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }


                /****Mail****/


                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Create(EventsDetailViewModel model)
        {
            var requireSecretCode = await GetSiteSettingBoolAsync(
                SiteSettingKey.Events.RequireBadge);

            if (model.Event.AllDay)
            {
                if (model.Event.EndDate.HasValue && model.Event.StartDate > model.Event.EndDate)
                {
                    ModelState.AddModelError("Event.EndDate", "The End date cannot be before the Start date");
                }
            }
            else
            {
                if (model.Event.EndDate.HasValue && model.Event.StartDate.TimeOfDay
                    > model.Event.EndDate.Value.TimeOfDay)
                {
                    ModelState.AddModelError("Event.EndDate", "The End time cannot be before the Start time");
                }
            }
            if (model.UseLocation && !model.Event.AtLocationId.HasValue)
            {
                ModelState.AddModelError("Event.AtLocationId", "The At Location field is required.");
            }
            if (!model.UseLocation && !model.Event.AtBranchId.HasValue)
            {
                ModelState.AddModelError("Event.AtBranchId", "The At Branch field is required.");
            }
            if (model.IncludeSecretCode || requireSecretCode)
            {
                if (string.IsNullOrWhiteSpace(model.BadgeMakerImage) && model.BadgeUploadImage == null)
                {
                    ModelState.AddModelError("BadgemakerImage", "A badge is required.");
                }
                else if (model.BadgeUploadImage != null &&
                         (string.IsNullOrWhiteSpace(model.BadgeMakerImage) || !model.UseBadgeMaker) &&
                         (Path.GetExtension(model.BadgeUploadImage.FileName).ToLower() != ".jpg" &&
                          Path.GetExtension(model.BadgeUploadImage.FileName).ToLower() != ".jpeg" &&
                          Path.GetExtension(model.BadgeUploadImage.FileName).ToLower() != ".png"))
                {
                    ModelState.AddModelError("BadgeUploadImage", "Please use a .jpg or .png image.");
                }
            }
            else
            {
                ModelState.Remove(nameof(model.SecretCode));
                ModelState.Remove(nameof(model.AwardMessage));
                ModelState.Remove(nameof(model.AwardPoints));
            }

            if (!string.IsNullOrWhiteSpace(model.Event.ExternalLink))
            {
                try
                {
                    model.Event.ExternalLink = new UriBuilder(
                        model.Event.ExternalLink).Uri.AbsoluteUri;
                }
                catch (Exception)
                {
                    ModelState.AddModelError("Event.ExternalLink", "Invalid URL");
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (model.Event.ChallengeId.HasValue)
                    {
                        model.Event.ChallengeGroupId = null;
                    }
                    if (model.Event.AllDay)
                    {
                        model.Event.StartDate = model.Event.StartDate.Date;
                        if (model.Event.EndDate.HasValue)
                        {
                            if (model.Event.EndDate.Value.Date == model.Event.StartDate.Date)
                            {
                                model.Event.EndDate = null;
                            }
                            else
                            {
                                model.Event.EndDate = model.Event.EndDate.Value.Date;
                            }
                        }
                    }
                    else
                    {
                        if (model.Event.EndDate.HasValue)
                        {
                            if (model.Event.EndDate.Value.TimeOfDay == model.Event.StartDate.TimeOfDay)
                            {
                                model.Event.EndDate = null;
                            }
                            else
                            {
                                model.Event.EndDate = model.Event.StartDate.Date
                                                      + model.Event.EndDate.Value.TimeOfDay;
                            }
                        }
                    }

                    int?triggerId = null;
                    if (model.IncludeSecretCode)
                    {
                        byte[] badgeBytes;
                        string filename;
                        if (!string.IsNullOrWhiteSpace(model.BadgeMakerImage) &&
                            (model.BadgeUploadImage == null || model.UseBadgeMaker))
                        {
                            var badgeString = model.BadgeMakerImage.Split(',').Last();
                            badgeBytes = Convert.FromBase64String(badgeString);
                            filename   = "badge.png";
                        }
                        else
                        {
                            using (var fileStream = model.BadgeUploadImage.OpenReadStream())
                            {
                                using (var ms = new MemoryStream())
                                {
                                    fileStream.CopyTo(ms);
                                    badgeBytes = ms.ToArray();
                                }
                            }
                            filename = Path.GetFileName(model.BadgeUploadImage.FileName);
                        }
                        Badge newBadge = new Badge()
                        {
                            Filename = filename
                        };
                        var badge = await _badgeService.AddBadgeAsync(newBadge, badgeBytes);

                        Trigger trigger = new Trigger
                        {
                            Name         = $"Event '{model.Event.Name}' code",
                            SecretCode   = model.SecretCode,
                            AwardMessage = model.AwardMessage,
                            AwardPoints  = model.AwardPoints,
                            AwardBadgeId = badge.Id,
                        };
                        triggerId = (await _triggerService.AddAsync(trigger)).Id;
                    }

                    var graEvent = model.Event;
                    if (model.UseLocation)
                    {
                        graEvent.AtBranchId = null;
                    }
                    else
                    {
                        graEvent.AtLocationId = null;
                    }
                    graEvent.IsActive = true;
                    graEvent.IsValid  = true;

                    if (triggerId.HasValue)
                    {
                        graEvent.RelatedTriggerId = triggerId;
                    }

                    await _eventService.Add(graEvent);

                    ShowAlertSuccess($"Event '{graEvent.Name}' created.");
                    if (graEvent.IsCommunityExperience)
                    {
                        return(RedirectToAction("CommunityExperiences"));
                    }
                    return(RedirectToAction("Index"));
                }
                catch (GraException gex)
                {
                    ShowAlertWarning("Could not create event: ", gex.Message);
                }
            }
            PageTitle = "Create Event";

            var systemList = await _siteService.GetSystemList(true);

            var branchList = await _siteService.GetBranches(model.SystemId, true);

            var locationList = await _eventService.GetLocations();

            var programList = await _siteService.GetProgramList();

            model.SystemList        = new SelectList(systemList, "Id", "Name");
            model.BranchList        = new SelectList(branchList, "Id", "Name");
            model.LocationList      = new SelectList(locationList, "Id", "Name");
            model.ProgramList       = new SelectList(programList, "Id", "Name");
            model.RequireSecretCode = requireSecretCode;
            return(View(model));
        }
Ejemplo n.º 16
0
 public void Add()
 {
     Add(EventService.Add());
 }