Ejemplo n.º 1
0
        public async Task <Apponintment> UpdateAppointment(Apponintment apponintment)
        {
            var app = _calendarContext.Apponintments.FirstOrDefault(x => x.Id == apponintment.Id);

            app.From        = apponintment.From;
            app.Categoria   = apponintment.Categoria;
            app.Title       = apponintment.Title;
            app.Description = apponintment.Description;
            app.StartDate   = apponintment.StartDate;
            app.ClassEvent  = apponintment.ClassEvent;
            app.SpecifiedID = _calendarContext.IDSpecifications.FirstOrDefault(x => x.AppointmentId == apponintment.Id);
            if (app?.SpecifiedID == null)
            {
                return(null);
            }
            _calendarContext.Apponintments.Update(app);
            var res = await _calendarContext.SaveEntitiesAsync();

            if (res)
            {
                return(app);
            }
            else
            {
                return(null);
            }
        }
        public async Task <bool> Handle(UpdateAppointmentCommand request, CancellationToken cancellationToken)
        {
            var result = false;
            var appointmentToUpdate = new Apponintment()
            {
                Categoria   = request.Categoria,
                ClassEvent  = request.ClassEvent,
                Description = request.Description,
                From        = request.From,
                StartDate   = request.StartDate,
                Id          = request.Id,
                Title       = request.Title,
                To          = request.To
            };
            var res = await _calendarRepository.UpdateAppointment(appointmentToUpdate);

            if (res != null)
            {
                var GoogleEventModel = new GoogleEventModel()
                {
                    EventId     = res.SpecifiedID.GoogleId,
                    Description = res.Description,
                    Start       = res.StartDate,
                    End         = res.StartDate.AddMinutes(15),
                    Summary     = res.Title,
                };
                result = await _googleCalendarRepository.UpdateEvent(GoogleEventModel, "primary") != null;
            }
            return(result);
        }
        private Apponintment MapItem(dynamic result)
        {
            var app = new Apponintment
            {
                Id          = result[0].Id,
                StartDate   = result[0].StartDate,
                Categoria   = result[0].Categoria,
                ClassEvent  = result[0].ClassEvent,
                Description = result[0].Description,
                From        = result[0].From,
                Title       = result[0].Title,
                To          = result[0].To
            };

            return(app);
        }
Ejemplo n.º 4
0
        public async Task <Apponintment> CreateAppointment(Apponintment apponintment)
        {
            var _eventID = Guid.NewGuid().ToString().Replace("-", string.Empty);
            var Idspec   = new IDSpecification
            {
                AppointmentId = apponintment.Id,
                GoogleId      = _eventID
            };

            _calendarContext.IDSpecifications.Add(Idspec);
            apponintment.SpecifiedID = Idspec;
            _calendarContext.Apponintments.Add(apponintment);
            var result = await _calendarContext.SaveEntitiesAsync();

            if (result)
            {
                return(apponintment);
            }
            else
            {
                return(null);
            }
        }