Exemple #1
0
        public async Task <IActionResult> UpdateCalendarEventAsync(CalendarEvent calendarEvent,
                                                                   [FromServices] IMongoCollection <CalendarEvent> mongoCollection)
        {
            if (calendarEvent == null || !calendarEvent.AreValuesCorrect())
            {
                return(this.Error(HttpStatusCode.UnprocessableEntity,
                                  "CalendarEvent is null or it's properties are empty!"));
            }
            CalendarEvent currentValue = await mongoCollection.FirstOrDefaultAsync(x => x.Id == calendarEvent.Id);

            if (currentValue == null)
            {
                return(this.Error(HttpStatusCode.UnprocessableEntity,
                                  "Sended CalendarEvent to update has altered Id! Unable to update value!"));
            }
            UpdateResult result = await mongoCollection.UpdateOneAsync(x => x.Id == calendarEvent.Id,
                                                                       Extensions.GenerateUpdateDefinition(currentValue, calendarEvent));

            if (result.IsAcknowledged)
            {
                return(this.Success(""));
            }
            else
            {
                return(this.Error(HttpStatusCode.InternalServerError, "Value wasn't updated!"));
            }
        }
Exemple #2
0
        public async Task <IActionResult> AddCalendarEventAsync(CalendarEvent calendarEvent, [FromServices] IMongoCollection <CalendarEvent> mongoCollection)
        {
            if (calendarEvent == null || !calendarEvent.AreValuesCorrect())
            {
                return(new JsonResult(new { Type = "Error", Details = "CalendarEvent is null or it's properties are empty!" }));
            }
            calendarEvent.ID = Guid.NewGuid();
            await mongoCollection.InsertOneAsync(calendarEvent);

            return(new JsonResult(new { Type = "Success", Details = calendarEvent.ID }));
        }
Exemple #3
0
        public async Task <IActionResult> AddCalendarEventAsync(CalendarEvent calendarEvent,
                                                                [FromServices] IMongoCollection <CalendarEvent> mongoCollection,
                                                                [FromServices] IMongoCollection <Notification> notificationsCollection)
        {
            if (calendarEvent == null || !calendarEvent.AreValuesCorrect())
            {
                return(this.Error(HttpStatusCode.UnprocessableEntity,
                                  "CalendarEvent is null or it's properties are empty!"));
            }
            calendarEvent.Id = Guid.NewGuid();
            await mongoCollection.InsertOneAsync(calendarEvent);

            await this.AddNotificationAsync(
                new NewEventNotification(Guid.NewGuid(), calendarEvent.ForWho, calendarEvent.CreatorEmail,
                                         calendarEvent.Id), notificationsCollection);

            return(this.Success(calendarEvent.Id));
        }
Exemple #4
0
        public async Task <IActionResult> UpdateCalendarEventAsync(CalendarEvent calendarEvent, [FromServices] IMongoCollection <CalendarEvent> mongoCollection)
        {
            if (calendarEvent == null || !calendarEvent.AreValuesCorrect())
            {
                return(new JsonResult(new { Type = "Error", Details = "CalendarEvent is null or it's properties are empty!" }));
            }
            CalendarEvent currentValue = await mongoCollection.FirstOrDefaultAsync(x => x.ID == calendarEvent.ID);

            if (currentValue == null)
            {
                return(new JsonResult(new { Type = "Error", Details = "Sended CalendarEvent to update has altered ID! Unable to update value!" }));
            }
            UpdateResult result = await mongoCollection.UpdateOneAsync(x => x.ID == calendarEvent.ID, Extensions.GenerateUpdateDefinition <CalendarEvent> (currentValue, calendarEvent));

            if (result.IsAcknowledged)
            {
                return(new JsonResult(new { Type = "Success", Details = "" }));
            }
            ;