예제 #1
0
        public async Task <JsonResult> Start()
        {
            var id      = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var pomidor = context.Pomidors.FirstOrDefault(x => x.UserID == id);

            if (pomidor == null)
            {
                pomidor = new Pomidor()
                {
                    UserID = id
                };
                pomidor.Start(25);
                context.Pomidors.Add(pomidor);
                await context.SaveChangesAsync();
            }
            else
            {
                pomidor.Start(25);
                context.Update(pomidor);
                await context.SaveChangesAsync();
            }
            return(new JsonResult(new TimerJSON {
                Rest = pomidor.Rest.TotalMilliseconds, IsPomidor = true
            }));
        }