public async Task <IActionResult> CreateNewCall([FromBody] Call call) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Calls.Add(call); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCall", new { id = call.Id }, call)); }
public async Task <IActionResult> CreateNewService([FromBody] ExtraService service) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.ExtraServices.Add(service); await _context.SaveChangesAsync(); return(CreatedAtAction("GetExtraService", new { id = service.Id }, service)); }
public async Task <IActionResult> CreateNewTariff([FromBody] TariffPlan tar) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.TariffPlans.Add(tar); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTariff", new { id = tar.Id }, tar)); }
public async Task <IActionResult> CreateNewAddBalance([FromBody] AddBalance addBalance) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var client = await _context.Clients.Where(i => i.Id == addBalance.IdClient).FirstOrDefaultAsync(); client.Balance = client.Balance + addBalance.SumForAdd; _context.AddBalances.Add(addBalance); await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <Client> DeleteClientById(string id) { var item = _context.Clients.Find(id); if (item == null) { return(null); } _context.Clients.Remove(item); try { await _context.SaveChangesAsync(); } catch (Exception e) { Console.WriteLine(e.Message); //throw; } return(item); }
public async Task <IActionResult> UpdateClient([FromRoute] int id, [FromBody] Client client) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var item = _context.Clients.Find(id); if (item == null) { return(NotFound()); } //блок перезаписи данных if (item.Name != null && client.Name != null)//физическое лицо { item.Name = client.Name; item.SurName = client.SurName; item.NumberPassport = client.NumberPassport; item.DateOfBirth = client.DateOfBirth; } else//юридическое лицо { item.NameOrganization = client.NameOrganization; item.LegalAdress = client.LegalAdress; item.StartDate = client.StartDate; item.Itn = client.Itn; } //общие параметры item.Balance = client.Balance; item.DateConnect = client.DateConnect; item.FreeGb = client.FreeGb; item.FreeMin = client.FreeMin; item.FreeSms = client.FreeSms; item.IsPhysCl = client.IsPhysCl; item.Password = client.Password; item.PhoneNumber = client.PhoneNumber; _context.Clients.Update(item); await _context.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> Register([FromBody] RegisterViewModel model) { if (ModelState.IsValid) { Client client; ConnectTariff conTar; if (!String.IsNullOrEmpty(model.NameClient.ToString()) && String.IsNullOrEmpty(model.nameOrganisation.ToString())) { /// <summary> /// регистрация физ лица /// </summary> client = new Client { PhoneNumber = model.LoginPhoneNumber, UserName = model.LoginPhoneNumber, Balance = 0, DateConnect = DateTime.Now, DateOfBirth = model.DateOfBirthClient, Email = "ads", EmailConfirmed = true, FreeGb = 0, FreeMin = 0, FreeSms = 0, IsPhysCl = true, Name = model.NameClient, NormalizedEmail = "ads", NormalizedUserName = model.LoginPhoneNumber, NumberPassport = model.PassportClient, Password = model.Password, PhoneNumberConfirmed = true, SurName = model.SurNameClient }; } else { /// <summary> ///регистрация юр лица /// </summary> client = new Client { PhoneNumber = model.LoginPhoneNumber, UserName = model.LoginPhoneNumber, Balance = 0, DateConnect = DateTime.Now, Email = "ads", EmailConfirmed = true, FreeGb = 0, FreeMin = 0, FreeSms = 0, IsPhysCl = false, NormalizedEmail = "ads", NormalizedUserName = model.LoginPhoneNumber, Password = model.Password, PhoneNumberConfirmed = true, Itn = model.itn, LegalAdress = model.legalAddress, NameOrganization = model.nameOrganisation, StartDate = model.dateStartWorkOrganisation }; } // Добавление нового пользователя var result = await _clientManager.CreateAsync(client, model.Password); if (result.Succeeded) { // установка куки await _clientManager.AddToRoleAsync(client, "user"); await _signInManager.SignInAsync(client, false); var msg = new { message = "Добавлен новый пользователь: " + client.UserName }; if (client.IsPhysCl) { conTar = new ConnectTariff { DateConnectTariffBegin = DateTime.Now, DateConnectTariffEnd = null, IdClient = client.Id, IdTariffPlan = 2 } } ; else { conTar = new ConnectTariff { DateConnectTariffBegin = DateTime.Now, DateConnectTariffEnd = null, IdClient = client.Id, IdTariffPlan = 3 } }; _context.ConnectTariffs.Add(conTar); await _context.SaveChangesAsync(); return(Ok(msg)); } else { foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } var errorMsg = new { message = "Пользователь не добавлен.", error = ModelState.Values.SelectMany(e => e.Errors.Select(er => er.ErrorMessage)) }; return(Ok(errorMsg)); } } else { var errorMsg = new { message = "Неверные входные данные.", error = ModelState.Values.SelectMany(e => e.Errors.Select(er => er.ErrorMessage)) }; return(Ok(errorMsg)); } }