Esempio n. 1
0
        public async Task <JsonResult> AddEvent(ReqAddEvent req)
        {
            try
            {
                var user = await _userRepository.GetUser(User.Identity.Name);

                if (user != null)
                {
                    var calendarEvent = new CalendarEvent
                    {
                        CreateByUserId = user.Id,
                        Title          = req.Event.Title,
                        Details        = req.Event.Details,
                        StartDate      = req.Event.StartDate,
                        EndDate        = req.Event.EndDate,
                        EventType      = req.Event.EventType
                    };
                    if (req.Event.EventType.ToLower() == "personal")
                    {
                        calendarEvent.ForeignId = user.Id;
                    }
                    else
                    {
                        calendarEvent.ForeignId = ObjectId.Parse(user.CurrentOrganisation);
                    }
                    await _calendarEventRepository.CreateSync(calendarEvent);

                    var result = new JsonGenericResult
                    {
                        IsSuccess = true,
                        Result    = calendarEvent.Id
                    };
                    return(Json(result));
                }
                var ErrorResult = new JsonGenericResult
                {
                    IsSuccess = false,
                    Message   = "Error adding event."
                };
                return(Json(ErrorResult));
            }
            catch (Exception ex)
            {
                return(Json(new JsonGenericResult
                {
                    IsSuccess = false,
                    Message = ex.Message
                }));
            }
        }