Exemplo n.º 1
0
 public async Task <IActionResult> AddWorkLine(string usrlogin, string wlname)
 {
     using (var holder = new WorkCheckHolder(Configuration["ConnectionStrings:database"]))
     {
         return(Ok(await holder.AddWorkLine(usrlogin, wlname)));
     }
 }
Exemplo n.º 2
0
 public async Task <IActionResult> SetPeriod(string usrlogin, string wlname, int tstart, int tfinish)
 {
     using (var holder = new WorkCheckHolder(Configuration["ConnectionStrings:database"]))
     {
         return(Ok(await holder.AddPeriod(usrlogin, wlname, tstart, tfinish)));
     }
 }
Exemplo n.º 3
0
        public async Task <Message> Register(string mail, string login, string password)
        {
            try
            {
                if (_cont.Users.FirstOrDefault(x => x.Mail == mail) != null)
                {
                    return(new Message {
                        Code = MessageCode.error, Text = "This mail is already in use"
                    });
                }

                if (_cont.Users.FirstOrDefault(x => x.Login == login) != null)
                {
                    return(new Message {
                        Code = MessageCode.error, Text = "This login is already in use"
                    });
                }

                _cont.Users.Add(new User {
                    Login = login, Mail = mail, Password = password
                });

                await _cont.SaveChangesAsync();

                var user = _cont.Users.FirstOrDefault(x => x.Mail == mail);

                using (var holder = new WorkCheckHolder(_cont))
                {
                    await holder.AddWorkLine(user.Login, "Работа");

                    await holder.AddWorkLine(user.Login, "Хобби");

                    await holder.AddWorkLine(user.Login, "Спорт");

                    return(new Message {
                        Code = MessageCode.success, Text = "new user added", Data = user
                    });
                }
            }
            catch (Exception exc)
            {
                return(new Message {
                    Code = MessageCode.error, Text = exc.Message, Data = exc.StackTrace
                });
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> GetReport(string usrlogin, string wlname, int period)
        {
            using (var holder = new WorkCheckHolder(Configuration["ConnectionStrings:database"]))
            {
                switch (period)
                {
                case (int)PeriodTypes.Day:
                    return(Ok(await holder.GetDayPeriods(usrlogin, wlname)));

                case (int)PeriodTypes.Week:
                    return(Ok(await holder.GetWeekPeriods(usrlogin, wlname)));

                case (int)PeriodTypes.Month:
                    return(Ok(await holder.GetMonthPeriods(usrlogin, wlname)));

                default:
                    return(Ok(new Message {
                        Code = MessageCode.error, Text = "Wrong period"
                    }));
                }
            }
        }