예제 #1
0
        public override DateTimeDto ConvertDateTime(MemberInfo member, object value)
        {
            DateTimeDto result = new DateTimeDto();

            if (member != null)
            {
                result.Member = member;

                string valueOfTime = null;
                if (member == ResolveConstants.PropertyInfo_DateTime_Now)
                {
                    valueOfTime = ("GETDATE()");
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_UtcNow)
                {
                    valueOfTime = ("GETUTCDATE()");
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_Today)
                {
                    valueOfTime = BuildCastState("GETDATE()", "DATE", false);
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_Date)
                {
                    valueOfTime = BuildCastState(value, "DATE", false);
                }
                else if (this.IsDatePart(member, value, out valueOfTime))
                {
                    // return exp;
                }
                result.Text = valueOfTime;
            }

            return(result);
        }
예제 #2
0
        public void Delete(DateTimeDto request)
        {
            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!(request?.Id > 0))
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No Id provided for delete.");
                    }

                    var en = DocEntityDateTime.Get(request?.Id);
                    if (null == en)
                    {
                        throw new HttpError(HttpStatusCode.NotFound, $"No DateTime could be found for Id {request?.Id}.");
                    }
                    if (en.IsRemoved)
                    {
                        return;
                    }

                    if (!DocPermissionFactory.HasPermission(en, currentUser, DocConstantPermission.DELETE))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have DELETE permission for this route.");
                    }

                    en.Remove();

                    DocCacheClient.RemoveSearch(DocConstantModelName.DATETIME);
                    DocCacheClient.RemoveById(request.Id);
                });
            }
        }
예제 #3
0
        private DateTimeDto GetDateTime(DateTimeDto request)
        {
            var         id    = request?.Id;
            DateTimeDto ret   = null;
            var         query = DocQuery.ActiveQuery ?? Execute;

            DocPermissionFactory.SetSelect <DateTimeDto>(currentUser, "DateTime", request.Select);

            DocEntityDateTime entity = null;

            if (id.HasValue)
            {
                entity = DocEntityDateTime.Get(id.Value);
            }
            if (null == entity)
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No DateTime found for Id {id.Value}");
            }

            if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.VIEW))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have VIEW permission for this route.");
            }

            ret = entity?.ToDto();
            return(ret);
        }
예제 #4
0
        public override DateTimeDto ConvertDateTime(MemberInfo member, object value)
        {
            DateTimeDto result = new DateTimeDto();

            if (member != null)
            {
                result.Member = member;

                string valueOfTime = null;
                if (member == ResolveConstants.PropertyInfo_DateTime_Now)
                {
                    valueOfTime = ("NOW()");
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_UtcNow)
                {
                    valueOfTime = ("CURRENT_TIMESTAMP");
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_Today)
                {
                    valueOfTime = ("CURRENT_DATE");
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_Date)
                {
                    valueOfTime = "DATE(" + value + ")";
                }
                else if (this.IsDatePart(member, value, out valueOfTime))
                {
                    // return exp;
                }
                result.Text = valueOfTime;
            }

            return(result);
        }
        public async Task <IActionResult> IndexAsync()
        {
            const string nowKey = "RedisCachedNowController_IndexAsync";

            string serialized = await _distributedCache.GetStringAsync(nowKey);

            if (serialized != null)
            {
                _logger.LogInformation("From redis");
                return(Ok(JsonSerializer.Deserialize <DateTimeDto>(serialized)));
            }

            _logger.LogInformation("Current date is requested");
            var response = DateTimeDto.Now();

            await _distributedCache.SetStringAsync(
                key : nowKey,
                value : JsonSerializer.Serialize(response),
                options : new DistributedCacheEntryOptions
            {
                SlidingExpiration = TimeSpan.FromSeconds(3)
            });

            return(Ok(response));
        }
예제 #6
0
        public DateTimeDto Post(DateTimeDto request)
        {
            if (request == null)
            {
                throw new HttpError(HttpStatusCode.NotFound, "Request cannot be null.");
            }

            request.Select = request.Select ?? new List <string>();

            DateTimeDto ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    if (!DocPermissionFactory.HasPermissionTryAdd(currentUser, "DateTime"))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    ret = _AssignValues(request, DocConstantPermission.ADD, ssn);
                });
            }
            return(ret);
        }
예제 #7
0
        public override DateTimeDto ConvertDateTime(MemberInfo member, object value)
        {
            DateTimeDto result = new DateTimeDto();

            if (member != null)
            {
                result.Member = member;

                string valueOfTime = null;
                if (member == ResolveConstants.PropertyInfo_DateTime_Now)
                {
                    valueOfTime = "SYSDATE";// ("SYSTIMESTAMP");//SYSDATE
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_UtcNow)
                {
                    valueOfTime = ("SYS_EXTRACT_UTC(SYSTIMESTAMP)");
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_Today)
                {
                    valueOfTime = "TRUNC(SYSDATE,'DD')";
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_Date)//日期部分
                {
                    valueOfTime = "TRUNC(" + value + ",'DD')";
                }
                else if (this.IsDatePart(member, value, out valueOfTime))
                {
                    // return exp;
                }
                result.Text = valueOfTime;
            }

            return(result);
        }
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            [CosmosDB("DateTimeList", "Items", ConnectionStringSetting = "CosmosDBConnectionString", CreateIfNotExists = true)] out DateTimeDto document,
            ILogger log)
        {
            var utcNow = DateTime.UtcNow;

            document = new DateTimeDto
            {
                DateTime = utcNow
            };
            log.LogInformation($"DateTime {utcNow} submitted");

            return(new OkObjectResult($"DateTime {utcNow} submitted"));
        }
예제 #9
0
        public IActionResult GetCurrentExamForStudent([FromQuery] DateTimeDto dateTimedto)
        {
            var userId   = dateTimedto.UserId;
            var dateTime = new DateTime(dateTimedto.Year, dateTimedto.Month, dateTimedto.Day, dateTimedto.Hour, dateTimedto.Minit, 0);
            var exams    = this.Context.Exams
                           .Include(c => c.Questions)
                           .ThenInclude(c => c.StudentAnswers)
                           .ToList();
            var exam = exams
                       .Where(c => c.Date.Year == dateTime.Year && c.Date.Month == dateTime.Month && c.Date.Day == dateTime.Day).OrderBy(c => c.Date)
                       .FirstOrDefault();

            if (exam == null)
            {
                return(Ok(false));
            }
            if (exam.Questions.Any(c => c.StudentAnswers.Any(c => c.StudentId == userId)))
            {
                return(Conflict());
            }
            ExamStudentDto examStudentDto = new ExamStudentDto()
            {
                Id       = exam.Id,
                Title    = exam.Title,
                Date     = exam.Date,
                Question = new List <GetQuestionStudnetDto>()
            };

            foreach (var item in exam.Questions)
            {
                examStudentDto.Question.Add(new GetQuestionStudnetDto()
                {
                    Id       = item.Id,
                    Choise1  = item.Choise1,
                    Choise2  = item.Choise2,
                    Choise3  = item.Choise3,
                    Choise4  = item.Choise4,
                    Question = item.Question1,
                    Time     = item.Time
                });
            }
            var questions = examStudentDto.Question;

            return(Ok(new { examStudentDto, questions }));
        }
예제 #10
0
        public DateTimeDto Patch(DateTimeDto request)
        {
            if (true != (request?.Id > 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, "Please specify a valid Id of the DateTime to patch.");
            }

            request.Select = request.Select ?? new List <string>();

            DateTimeDto ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    ret = _AssignValues(request, DocConstantPermission.EDIT, ssn);
                });
            }
            return(ret);
        }
예제 #11
0
        public DateTimeDto Post(DateTimeDtoCopy request)
        {
            DateTimeDto ret = null;

            using (Execute)
            {
                Execute.Run(ssn =>
                {
                    var entity = DocEntityDateTime.Get(request?.Id);
                    if (null == entity)
                    {
                        throw new HttpError(HttpStatusCode.NoContent, "The COPY request did not succeed.");
                    }
                    if (!DocPermissionFactory.HasPermission(entity, currentUser, DocConstantPermission.ADD))
                    {
                        throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
                    }

                    var pDateDay   = entity.DateDay;
                    var pDateMonth = entity.DateMonth;
                    var pDateTime  = entity.DateTime;
                    var pDateYear  = entity.DateYear;
                    var copy       = new DocEntityDateTime(ssn)
                    {
                        Hash        = Guid.NewGuid()
                        , DateDay   = pDateDay
                        , DateMonth = pDateMonth
                        , DateTime  = pDateTime
                        , DateYear  = pDateYear
                    };

                    copy.SaveChanges(DocConstantPermission.ADD);
                    ret = copy.ToDto();
                });
            }
            return(ret);
        }
예제 #12
0
        public override DateTimeDto ConvertDateTime(MemberInfo member, object value)
        {
            DateTimeDto result = new DateTimeDto();

            if (member != null)
            {
                result.Member = member;

                string valueOfTime = null;
                if (member == ResolveConstants.PropertyInfo_DateTime_Now)
                {
                    valueOfTime = ("DATETIME('NOW','LOCALTIME')");
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_UtcNow)
                {
                    valueOfTime = ("DATETIME()");
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_Today)
                {
                    valueOfTime = ("DATE('NOW','LOCALTIME')");
                }
                else if (member == ResolveConstants.PropertyInfo_DateTime_Date)
                {
                    valueOfTime  = ("DATETIME(DATE(");
                    valueOfTime += value;
                    valueOfTime += ("))");
                }
                else if (this.IsDatePart(member, value, out valueOfTime))
                {
                    // return exp;
                }
                result.Text = valueOfTime;
            }

            return(result);
        }
예제 #13
0
 public object Get(DateTimeDto request) => GetEntityWithCache <DateTimeDto>(DocConstantModelName.DATETIME, request, GetDateTime);
        public void CanSerializeDates()
        {
            var p = DateTimeDto.Create(101);

            Assert.IsTrue(this.Serializer.CanSerializeString <DateTimeDto>(p));
        }
예제 #15
0
        public static string GetDateTimeStringFromJavaLocalDateTimeFormat(string javaFormat)
        {
            DateTimeDto dateTimeObj = JsonConvert.DeserializeObject <DateTimeDto>(javaFormat, GetDeserializeSettings());

            return(string.Format("{0}.{1}.{2} {3}:{4}:{5}", dateTimeObj.Date.Day, dateTimeObj.Date.Month, dateTimeObj.Date.Year, dateTimeObj.Time.Hour, dateTimeObj.Time.Minute, dateTimeObj.Time.Second));
        }
예제 #16
0
 public static string GetDateTimeStringFromJavaLocalDateTimeFormatDto(DateTimeDto datetime)
 {
     return(string.Format("{0}.{1}.{2} {3}:{4}:{5}", datetime.Date.Day, datetime.Date.Month, datetime.Date.Year, datetime.Time.Hour, datetime.Time.Minute, datetime.Time.Second));
 }
예제 #17
0
 public DateTimeDto Put(DateTimeDto request)
 {
     return(Patch(request));
 }
예제 #18
0
        private DateTimeDto _AssignValues(DateTimeDto request, DocConstantPermission permission, Session session)
        {
            if (permission != DocConstantPermission.ADD && (request == null || request.Id <= 0))
            {
                throw new HttpError(HttpStatusCode.NotFound, $"No record");
            }

            if (permission == DocConstantPermission.ADD && !DocPermissionFactory.HasPermissionTryAdd(currentUser, "DateTime"))
            {
                throw new HttpError(HttpStatusCode.Forbidden, "You do not have ADD permission for this route.");
            }

            request.Select = request.Select ?? new List <string>();

            DateTimeDto ret = null;

            request = _InitAssignValues <DateTimeDto>(request, permission, session);
            //In case init assign handles create for us, return it
            if (permission == DocConstantPermission.ADD && request.Id > 0)
            {
                return(request);
            }

            var cacheKey = GetApiCacheKey <DateTimeDto>(DocConstantModelName.DATETIME, nameof(DateTimeDto), request);

            //First, assign all the variables, do database lookups and conversions
            var pDateDay   = request.DateDay;
            var pDateMonth = request.DateMonth;
            var pDateTime  = request.DateTime;
            var pDateYear  = request.DateYear;
            var pArchived  = true == request.Archived;
            var pLocked    = request.Locked;

            var entity = InitEntity <DocEntityDateTime, DateTimeDto>(request, permission, session);

            if (AllowPatchValue <DateTimeDto, bool>(request, DocConstantModelName.DATETIME, pArchived, permission, nameof(request.Archived), pArchived != entity.Archived))
            {
                entity.Archived = pArchived;
            }
            if (AllowPatchValue <DateTimeDto, int?>(request, DocConstantModelName.DATETIME, pDateDay, permission, nameof(request.DateDay), pDateDay != entity.DateDay))
            {
                entity.DateDay = pDateDay;
            }
            if (AllowPatchValue <DateTimeDto, int?>(request, DocConstantModelName.DATETIME, pDateMonth, permission, nameof(request.DateMonth), pDateMonth != entity.DateMonth))
            {
                entity.DateMonth = pDateMonth;
            }
            if (AllowPatchValue <DateTimeDto, DateTime?>(request, DocConstantModelName.DATETIME, pDateTime, permission, nameof(request.DateTime), pDateTime != entity.DateTime))
            {
                entity.DateTime = pDateTime;
            }
            if (AllowPatchValue <DateTimeDto, int?>(request, DocConstantModelName.DATETIME, pDateYear, permission, nameof(request.DateYear), pDateYear != entity.DateYear))
            {
                entity.DateYear = pDateYear;
            }
            if (request.Locked && AllowPatchValue <DateTimeDto, bool>(request, DocConstantModelName.DATETIME, pArchived, permission, nameof(request.Locked), pLocked != entity.Locked))
            {
                entity.Archived = pArchived;
            }
            entity.SaveChanges(permission);

            var idsToInvalidate = new List <int>();

            if (idsToInvalidate.Any())
            {
                idsToInvalidate.Add(entity.Id);
                DocCacheClient.RemoveByEntityIds(idsToInvalidate);
                DocCacheClient.RemoveSearch(DocConstantModelName.DATETIME);
            }

            entity.SaveChanges(permission);
            DocPermissionFactory.SetSelect <DateTimeDto>(currentUser, nameof(DateTimeDto), request.Select);
            ret = entity.ToDto();

            var cacheExpires = DocResources.Metadata.GetCacheExpiration(DocConstantModelName.DATETIME);

            DocCacheClient.Set(key: cacheKey, value: ret, entityId: request.Id, entityType: DocConstantModelName.DATETIME, cacheExpires);

            return(ret);
        }