コード例 #1
0
        public CalendarEventDTO GetCalendarEvent(int calendarEventId)
        {
            try
            {
                //Requires.NotNegative("calendarEventId", calendarEventId);

                log.Debug("calendarEventId: " + calendarEventId + " ");

                // get
                R_CalendarEvent t = Repository.GetCalendarEvent(calendarEventId);

                CalendarEventDTO dto = new CalendarEventDTO(t);

                log.Debug(CalendarEventDTO.FormatCalendarEventDTO(dto));

                return(dto);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #2
0
        private CalendarEventDTO Create(CalendarEventViewModel viewModel)
        {
            try
            {
                log.Debug(CalendarEventViewModel.FormatCalendarEventViewModel(viewModel));

                CalendarEventDTO calendarEvent = new CalendarEventDTO();

                // copy values
                viewModel.UpdateDTO(calendarEvent, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                calendarEvent.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                calendarEvent.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_calendarEventService.AddCalendarEvent - " + CalendarEventDTO.FormatCalendarEventDTO(calendarEvent));

                int id = _calendarEventService.AddCalendarEvent(calendarEvent);

                calendarEvent.CalendarEventId = id;

                log.Debug("result: 'success', id: " + id);

                return(calendarEvent);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #3
0
        public static CalendarEventDTO SampleCalendarEventDTO(int id = 1)
        {
            CalendarEventDTO calendarEvent = new CalendarEventDTO();

            // int
            calendarEvent.CalendarEventId = id;
            // int?
            calendarEvent.NucleoId = 1;
            // string
            calendarEvent.Name = "NameTestValue";
            // string
            calendarEvent.Description = "DescriptionTestValue";
            // System.DateTime
            calendarEvent.StartDate = new System.DateTime();
            // System.DateTime
            calendarEvent.EndDate = new System.DateTime();
            // bool
            calendarEvent.Active = false;
            // bool
            calendarEvent.IsDeleted = false;
            // int?
            calendarEvent.CreateBy = 1;
            // System.DateTime?
            calendarEvent.CreateOn = new System.DateTime();
            // int?
            calendarEvent.UpdateBy = 1;
            // System.DateTime?
            calendarEvent.UpdateOn = new System.DateTime();

            return(calendarEvent);
        }
コード例 #4
0
        // POST api/calendarapi
        public HttpResponseMessage Post([FromBody] CalendarEventDTO calendarEventDTO)
        {
            if (ModelState.IsValid &&
                calendarEventDTO.StartTime >= DateTime.Now.AddHours(-1) &&  //Ensure entry is a valid start date and finish date
                calendarEventDTO.FinishTime > calendarEventDTO.StartTime)
            {
                var calendarEvent = Mapper.Map <CalendarEventDTO, CalendarEvent>(calendarEventDTO);
                calendarEvent.Id = Guid.NewGuid(); //Assign new ID on save.

                //Lookup Business and attach, so that no updates or inserts are performed on BusinessType lookup table
                calendarEvent.UserProfile = db.UserProfiles.Single(u => u.Email == User.Identity.Name);
                if (calendarEvent.UserProfile == null)
                {
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Userprofile is null"));
                }


                db.CalendarEvents.Add(calendarEvent);
                db.SaveChanges();

                calendarEventDTO = Mapper.Map <CalendarEvent, CalendarEventDTO>(calendarEvent);
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, calendarEventDTO);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = calendarEventDTO.Id }));
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
コード例 #5
0
        public void GetCalendarEventsPaged_Success_Test()
        {
            // Arrange
            string searchTerm = "";
            int    pageIndex  = 0;
            int    pageSize   = 10;

            // list
            IList <R_CalendarEvent> list = new List <R_CalendarEvent>();

            for (int i = 1; i <= pageSize; i++)
            {
                list.Add(SampleCalendarEvent(i));
            }

            // create mock for repository
            var mock = new Mock <ICalendarEventRepository>();

            mock.Setup(s => s.GetCalendarEvents(Moq.It.IsAny <string>(), Moq.It.IsAny <int>(), Moq.It.IsAny <int>())).Returns(list);

            // service
            CalendarEventService calendarEventService = new CalendarEventService();

            CalendarEventService.Repository = mock.Object;

            // Act
            var resultList          = calendarEventService.GetCalendarEvents(searchTerm, pageIndex, pageSize);
            CalendarEventDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.CalendarEventId);
            Assert.AreEqual(10, resultList.Count);
        }
コード例 #6
0
        public void GetCalendarEvents_Success_Test()
        {
            // Arrange
            R_CalendarEvent calendarEvent = SampleCalendarEvent(1);

            IList <R_CalendarEvent> list = new List <R_CalendarEvent>();

            list.Add(calendarEvent);

            // create mock for repository
            var mock = new Mock <ICalendarEventRepository>();

            mock.Setup(s => s.GetCalendarEvents()).Returns(list);

            // service
            CalendarEventService calendarEventService = new CalendarEventService();

            CalendarEventService.Repository = mock.Object;

            // Act
            var resultList          = calendarEventService.GetCalendarEvents();
            CalendarEventDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.CalendarEventId);
        }
コード例 #7
0
        public int AddCalendarEvent(CalendarEventDTO dto)
        {
            int id = 0;

            try
            {
                log.Debug(CalendarEventDTO.FormatCalendarEventDTO(dto));

                R_CalendarEvent t = CalendarEventDTO.ConvertDTOtoEntity(dto);

                // add
                id = Repository.AddCalendarEvent(t);
                dto.CalendarEventId = id;

                log.Debug("result: 'success', id: " + id);
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }

            return(id);
        }
コード例 #8
0
 public CalendarEventViewModel(CalendarEventDTO t)
 {
     CalendarEventId = t.CalendarEventId;
     NucleoId        = t.NucleoId;
     Name            = t.Name;
     Description     = t.Description;
     StartDate       = t.StartDate;
     EndDate         = t.EndDate;
     Active          = t.Active;
     IsDeleted       = t.IsDeleted;
     CreateBy        = t.CreateBy;
     CreateOn        = t.CreateOn;
     UpdateBy        = t.UpdateBy;
     UpdateOn        = t.UpdateOn;
 }
コード例 #9
0
        public async Task <HttpResponseMessage> Post(HttpRequestMessage request, [FromBody] CalendarEventDTO value)
        {
            try
            {
                var calendarEvent = Mapper.Map <CalendarEventDTO, CalendarEvent>(value);

                var htmlLink = googleCalendarService.AddEvent(calendarEvent);

                return(request.CreateResponse(HttpStatusCode.OK, htmlLink));
            }
            catch (Exception ex)
            {
                logger.Error(ex, JsonConvert.SerializeObject(value));

                return(request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
コード例 #10
0
        public CalendarEventDTO UpdateDTO(CalendarEventDTO dto, int?updateBy)
        {
            if (dto != null)
            {
                dto.CalendarEventId = this.CalendarEventId;
                dto.NucleoId        = this.NucleoId;
                dto.Name            = this.Name;
                dto.Description     = this.Description;
                dto.StartDate       = this.StartDate;
                dto.EndDate         = this.EndDate;
                dto.Active          = this.Active;
                dto.IsDeleted       = this.IsDeleted;

                dto.UpdateBy = updateBy;
                dto.UpdateOn = System.DateTime.UtcNow;
            }

            return(dto);
        }
コード例 #11
0
        public void UpdateCalendarEvent_Success_Test()
        {
            // Arrange
            CalendarEventDTO dto = SampleCalendarEventDTO(1);

            // create mock for repository
            var mock = new Mock <ICalendarEventRepository>();

            mock.Setup(s => s.UpdateCalendarEvent(Moq.It.IsAny <R_CalendarEvent>())).Verifiable();

            // service
            CalendarEventService calendarEventService = new CalendarEventService();

            CalendarEventService.Repository = mock.Object;

            // Act
            calendarEventService.UpdateCalendarEvent(dto);

            // Assert
            Assert.IsNotNull(dto);
        }
コード例 #12
0
        private CalendarEventDTO Update(CalendarEventViewModel viewModel)
        {
            try
            {
                log.Debug(CalendarEventViewModel.FormatCalendarEventViewModel(viewModel));

                // get
                log.Debug("_calendarEventService.GetCalendarEvent - calendarEventId: " + viewModel.CalendarEventId + " ");

                var existingCalendarEvent = _calendarEventService.GetCalendarEvent(viewModel.CalendarEventId);

                log.Debug("_calendarEventService.GetCalendarEvent - " + CalendarEventDTO.FormatCalendarEventDTO(existingCalendarEvent));

                if (existingCalendarEvent != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingCalendarEvent, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_calendarEventService.UpdateCalendarEvent - " + CalendarEventDTO.FormatCalendarEventDTO(existingCalendarEvent));

                    _calendarEventService.UpdateCalendarEvent(existingCalendarEvent);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingCalendarEvent: null, CalendarEventId: " + viewModel.CalendarEventId);
                }

                return(existingCalendarEvent);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #13
0
        public void AddCalendarEvent_Success_Test()
        {
            // Arrange
            CalendarEventDTO dto = SampleCalendarEventDTO(1);

            // create mock for repository
            var mock = new Mock <ICalendarEventRepository>();

            mock.Setup(s => s.AddCalendarEvent(Moq.It.IsAny <R_CalendarEvent>())).Returns(1);

            // service
            CalendarEventService calendarEventService = new CalendarEventService();

            CalendarEventService.Repository = mock.Object;

            // Act
            int id = calendarEventService.AddCalendarEvent(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.CalendarEventId);
        }
コード例 #14
0
        public void DeleteCalendarEvent(CalendarEventDTO dto)
        {
            try
            {
                log.Debug(CalendarEventDTO.FormatCalendarEventDTO(dto));

                R_CalendarEvent t = CalendarEventDTO.ConvertDTOtoEntity(dto);

                // delete
                Repository.DeleteCalendarEvent(t);
                dto.IsDeleted = t.IsDeleted;

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #15
0
        public void GetCalendarEvent_Success_Test()
        {
            // Arrange
            int             id            = 1;
            R_CalendarEvent calendarEvent = SampleCalendarEvent(id);

            // create mock for repository
            var mock = new Mock <ICalendarEventRepository>();

            mock.Setup(s => s.GetCalendarEvent(Moq.It.IsAny <int>())).Returns(calendarEvent);

            // service
            CalendarEventService calendarEventService = new CalendarEventService();

            CalendarEventService.Repository = mock.Object;

            // Act
            CalendarEventDTO result = calendarEventService.GetCalendarEvent(id);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.CalendarEventId);
        }
コード例 #16
0
        // PUT api/calendarapi/5
        public HttpResponseMessage Put(Guid id, [FromBody] CalendarEventDTO calendarEventDTO)
        {
            if (ModelState.IsValid &&
                calendarEventDTO.FinishTime > calendarEventDTO.StartTime)       //Ensure entry is a valid start date and finish date
            {
                var calendarEvent = db.CalendarEvents.Find(calendarEventDTO.Id);

                if (calendarEvent == null)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Unable to find calendar event with given id"));
                }

                if (calendarEvent.UserProfile.Email != User.Identity.Name)
                {
                    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "You are not authorised  to access this calendar event"));
                }

                try
                {
                    var calendarEventMOD = Mapper.Map <CalendarEventDTO, CalendarEvent>(calendarEventDTO, calendarEvent);

                    db.Entry(calendarEventMOD).State = EntityState.Modified;

                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
コード例 #17
0
        public void UpdateCalendarEvent(CalendarEventDTO dto)
        {
            try
            {
                //Requires.NotNull(t);
                //Requires.PropertyNotNegative(t, "CalendarEventId");

                log.Debug(CalendarEventDTO.FormatCalendarEventDTO(dto));

                R_CalendarEvent t = CalendarEventDTO.ConvertDTOtoEntity(dto);

                // update
                Repository.UpdateCalendarEvent(t);

                log.Debug("result: 'success'");
            }
            catch (System.Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
コード例 #18
0
        public async void CreateCalendarEvent(CalendarEventDTO calendarEvent)
        {
            var createCalendarEventCommand = new CreateCalendarEventCommand(calendarEvent.Description);

            await _bus.SendCommand(createCalendarEventCommand);
        }
コード例 #19
0
        public void GetCalendarEventListAdvancedSearch_Success_Test()
        {
            // Arrange
            int?   nucleoId    = null;
            string name        = null;
            string description = null;

            System.DateTime?startDateFrom = null;
            System.DateTime?startDateTo   = null;
            System.DateTime?endDateFrom   = null;
            System.DateTime?endDateTo     = null;
            bool?           active        = null;

            //int pageIndex = 0;
            int pageSize = 10;

            // list
            IList <R_CalendarEvent> list = new List <R_CalendarEvent>();

            for (int i = 1; i <= pageSize; i++)
            {
                list.Add(SampleCalendarEvent(i));
            }

            // create mock for repository
            var mock = new Mock <ICalendarEventRepository>();

            mock.Setup(s => s.GetCalendarEventListAdvancedSearch(
                           Moq.It.IsAny <int?>()               // nucleoId
                           , Moq.It.IsAny <string>()           // name
                           , Moq.It.IsAny <string>()           // description
                           , Moq.It.IsAny <System.DateTime?>() // startDateFrom
                           , Moq.It.IsAny <System.DateTime?>() // startDateTo
                           , Moq.It.IsAny <System.DateTime?>() // endDateFrom
                           , Moq.It.IsAny <System.DateTime?>() // endDateTo
                           , Moq.It.IsAny <bool?>()            // active
                           )).Returns(list);

            // service
            CalendarEventService calendarEventService = new CalendarEventService();

            CalendarEventService.Repository = mock.Object;

            // Act
            var resultList = calendarEventService.GetCalendarEventListAdvancedSearch(
                nucleoId
                , name
                , description
                , startDateFrom
                , startDateTo
                , endDateFrom
                , endDateTo
                , active
                );

            CalendarEventDTO result = resultList.FirstOrDefault();

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.CalendarEventId);
        }
コード例 #20
0
        public ActionResult CreateCalendarEvent(CalendarEventDTO calendarEventDTO)
        {
            _calendarService.CreateCalendarEvent(calendarEventDTO);

            return(Ok(calendarEventDTO));
        }