Exemplo n.º 1
0
        public async Task <IHttpActionResult> PutCalendar(CompanyCalendar cc)
        {
            Calendar calendar = db.Calendars.Single(c => c.Id == cc.Id);

            if (calendar == null)
            {
                return(NotFound());
            }

            db.Entry(calendar).State = EntityState.Modified;
            if (!String.IsNullOrEmpty(cc.Name))
            {
                calendar.Name = cc.Name;
            }
            if (!String.IsNullOrEmpty(cc.Name))
            {
                calendar.Description = cc.Description;
            }
            if (cc.DateFrom != null)
            {
                calendar.DateFrom = (DateTime)cc.DateFrom;
            }
            if (cc.TimeFrom != null)
            {
                calendar.TimeFrom = cc.TimeFrom;
            }
            if (cc.DateTo != null)
            {
                calendar.DateTo = (DateTime)cc.DateTo;
            }
            if (cc.TimeTo != null)
            {
                calendar.TimeTo = cc.TimeTo;
            }
            if (cc.WorkDaysNumber != null)
            {
                calendar.WorkDaysNumber = cc.WorkDaysNumber;
            }
            calendar.StatusId              = cc.StatusId;
            calendar.EventId               = cc.EventId;
            calendar.PositionRestriction   = cc.PositionRestriction;
            calendar.DepartmentRestriction = cc.DepartmentRestriction;
            calendar.IsActive              = cc.IsActive;
            if (cc.ParticipantTotalNumber != null)
            {
                calendar.ParticipantTotalNumber = cc.ParticipantTotalNumber;
            }
            if (cc.ParticipantAvailableNumber != null)
            {
                calendar.ParticipantAvailableNumber = cc.ParticipantAvailableNumber;
            }
            await db.SaveChangesAsync();

            return(StatusCode(HttpStatusCode.OK));
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> DeleteCalendar(CompanyCalendar cc)
        {
            Calendar calendar = db.Calendars.Single(c => c.Id == cc.Id);

            if (calendar == null)
            {
                return(NotFound());
            }

            db.Calendars.Remove(calendar);
            await db.SaveChangesAsync();

            return(Ok(calendar));
        }
Exemplo n.º 3
0
        public void Delete(int id)
        {
            _log.LogInformation($"Searching company calendar {id}");
            CompanyCalendar companyCalendar = _companyCalendarRepository.Query().Where(_ => _.Id == id).FirstOrDefault();

            if (companyCalendar == null)
            {
                throw new DeleteCompanyCalendarNotFoundException(id);
            }
            _log.LogInformation($"Deleting company calendar {id}");
            _companyCalendarRepository.Delete(companyCalendar);

            _unitOfWork.Complete();
        }
Exemplo n.º 4
0
 private void ValidateExistence(int id)
 {
     try
     {
         CompanyCalendar companyCalendar = _companyCalendarRepository.Query().Where(_ => _.Id == id).FirstOrDefault();
         if (companyCalendar == null)
         {
             throw new InvalidCompanyCalendarException("The Company calendar already exists .");
         }
     }
     catch (ValidationException ex)
     {
         throw new CreateContractInvalidException(ex.ToListOfMessages());
     }
 }
Exemplo n.º 5
0
        public void AddModelToGoogleCalendar(CompanyCalendar companyCalendar)
        {
            Event newEvent = new Event
            {
                Description = companyCalendar.Type,
                Summary     = companyCalendar.Comments,
                Start       = new EventDateTime()
                {
                    DateTime = new System.DateTime(companyCalendar.Date.Date.Year, companyCalendar.Date.Date.Month, companyCalendar.Date.Date.Day, 8, 0, 0)
                },
                End = new EventDateTime()
                {
                    DateTime = new System.DateTime(companyCalendar.Date.Date.Year, companyCalendar.Date.Date.Month, companyCalendar.Date.Date.Day, 19, 0, 0)
                }
            };

            _googleCalendarService.CreateEvent(newEvent);
        }
Exemplo n.º 6
0
        public async Task <int?> PostCalendar(CompanyCalendar cc)
        {
            Calendar calendar = new Calendar();

            if (!String.IsNullOrEmpty(cc.Name))
            {
                calendar.Name = cc.Name;
            }
            if (!String.IsNullOrEmpty(cc.Name))
            {
                calendar.Description = cc.Description;
            }
            if (cc.DateFrom != null)
            {
                calendar.DateFrom = (DateTime)cc.DateFrom;
            }
            if (cc.TimeFrom != null)
            {
                calendar.TimeFrom = cc.TimeFrom;
            }
            if (cc.DateTo != null)
            {
                calendar.DateTo = (DateTime)cc.DateTo;
            }
            if (cc.TimeTo != null)
            {
                calendar.TimeTo = cc.TimeTo;
            }
            if (cc.WorkDaysNumber != null)
            {
                calendar.WorkDaysNumber = cc.WorkDaysNumber;
            }
            if (db.Events.Single(e => e.Id == cc.EventId).Id > 0)
            {
                calendar.EventId = cc.EventId;
            }
            else
            {
                var eventId = db.Events.Single(e => e.Name == cc.EventName).Id;
                if (eventId > 0)
                {
                    calendar.EventId = eventId;
                }
            }

            if (db.Status.Single(s => s.Id == cc.StatusId && s.EventId == calendar.EventId).Id > 0)
            {
                calendar.StatusId = cc.StatusId;
            }
            else
            {
                var statusId = db.Status.Single(s => s.Name == cc.StatusName && s.EventId == calendar.EventId).Id;
                if (statusId > 0)
                {
                    calendar.StatusId = statusId;
                }
            }
            calendar.PositionRestriction   = cc.PositionRestriction;
            calendar.DepartmentRestriction = cc.DepartmentRestriction;
            calendar.IsActive = cc.IsActive;
            if (cc.ParticipantTotalNumber != null)
            {
                calendar.ParticipantTotalNumber = cc.ParticipantTotalNumber;
            }
            if (cc.ParticipantAvailableNumber != null)
            {
                calendar.ParticipantAvailableNumber = cc.ParticipantAvailableNumber;
            }

            if (!ModelState.IsValid)
            {
                return(null);
            }

            db.Calendars.Add(calendar);
            await db.SaveChangesAsync();

            return(calendar.Id);
        }