Beispiel #1
0
        public async Task <IActionResult> PutCTask(int id, CTask cTask)
        {
            if (id != cTask.Id)
            {
                return(BadRequest());
            }

            _context.Entry(cTask).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CTaskExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task Register()
        {
            RegisterModel model = JsonConvert.DeserializeObject <RegisterModel>(new System.IO.StreamReader(Request.Body).ReadLine());
            CUser         user  = _context.CUser.FirstOrDefault(u => u.Login == model.Login || u.Email == model.Email);

            if (user == null)
            {
                _context.CUser.Add(new CUser {
                    Login = model.Login, Email = model.Email, Password = _crypt.GetHash(model.Password), FirstName = model.FirstName, LastName = model.LastName
                });
                await _context.SaveChangesAsync();

                var identity = GetIdentity(model.Login, model.Password);
                var response = GenerateToken(identity);

                Response.ContentType = "application/json";
                await Response.WriteAsync(JsonConvert.SerializeObject(response, new JsonSerializerSettings {
                    Formatting = Formatting.Indented
                }));

                return;
            }
            else
            {
                Response.ContentType = "application/json";
                Response.StatusCode  = 400;
                await Response.WriteAsync("Пользователь с таким" + user.Login == model.Login? "логином" : "Email" + " уже существует");

                return;
            }
        }