public IHttpActionResult PostSalesperson([FromBody] Salesperson salesperson) { if (salesperson == null) { return(BadRequest("Invalid passed data")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } int newId = 0; try { newId = spDAO.Insert(salesperson); } catch (Exception e) { return(BadRequest(e.Message)); } return(CreatedAtRoute("DefaultApi", new { id = newId }, salesperson)); }
public void AssignSecondary(Salesperson person, District district) { if (person.Id < 1) { throw new DataLayerArgumentException("Invalid Salesperson ID!", new ArgumentOutOfRangeException()); } if (district.Id < 1) { throw new DataLayerArgumentException("Invalid District ID!", new ArgumentOutOfRangeException()); } string qry = $"exec spAssignSecondarySalesperson {person.Id},{district.Id}"; try { var link = conn.GetSqlConnection(); using (SqlCommand cmd = new SqlCommand(qry, link)) { link.Open(); var response = cmd.ExecuteReader(); link.Close(); } } catch (Exception e) { throw new DataLayerException("Cannot assign a secondary salesperson.", e); } }
public async Task <ActionResult <List <Salesperson> > > Test() { var models = new List <Salesperson>(); var connectionString = _config[SystemConstants.ConnectionStringKey]; using (var connection = new Npgsql.NpgsqlConnection(connectionString)) { await connection.OpenAsync(); var command = new Npgsql.NpgsqlCommand(@"SELECT v.businessentityid, v.emailaddress, v.firstname, v.lastname, v.phonenumber, v.territoryid FROM sales.vsalesperson AS v", connection); using (var reader = await command.ExecuteReaderAsync()) { while (await reader.ReadAsync()) { var model = new Salesperson(); model.BusinessEntityId = await reader.GetFieldValueAsync <int>(reader.GetOrdinal("businessentityid")); model.FirstName = await reader.GetFieldValueAsync <string>(reader.GetOrdinal("firstname")); model.TerritoryId = await reader.GetFieldValueAsync <int?>(reader.GetOrdinal("territoryid")); models.Add(model); } } } return(models); }
// PUT: api/Salesperson/5 public Salesperson Put(int id, [FromBody] Salesperson value) { if (value != null) { var faulted = new Salesperson(); faulted.IsFaulted = false; try { value.Id = id; db.Update(value); return(faulted); } catch (DatabaseLink.DataLayerArgumentException e) { faulted.IsFaulted = true; faulted.DataLayerArgumentException = e.Message; } catch (DatabaseLink.DataLayerException e) { faulted.IsFaulted = true; faulted.DataLayerException = e.Message; } return(faulted); } return(null); }
public async Task <IActionResult> PostSales([FromRoute] Salesperson sales) { _context.Salesperson.Add(sales); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSales", new { id = sales.SalespersonId }, sales)); }
public async Task <IActionResult> PutSales([FromRoute] int id, [FromRoute] Salesperson sales) { _context.Entry(sales).State = EntityState.Modified; await _context.SaveChangesAsync(); return(Ok(sales)); }
public ActionResult DeleteConfirmed(string id) { Salesperson salesperson = db.Salespersons.Find(id); db.Salespersons.Remove(salesperson); db.SaveChanges(); return RedirectToAction("Index"); }
public SaveResult SaveEdit(Salesperson sales, int userId, string userName) { var oldSales = BoDB.SalespersonDb.GetById(sales.Id); oldSales.ModifyBy = sales.ModifyBy; oldSales.ModifyTime = DateTime.UtcNow; oldSales.SaleName = sales.SaleName; oldSales.Position = sales.Position; oldSales.Gender = sales.Gender; oldSales.Mobile = sales.Mobile; BoDB.SalespersonDb.Update(oldSales); // Create ActionLog ActionLog actionLog = new ActionLog(); actionLog.IPAddress = GetClientIPAddress(); actionLog.AccountId = userId; actionLog.CreateTime = DateTime.UtcNow; actionLog.ModuleCode = typeof(SalespersonBLL).FullName + ".SaveEdit"; actionLog.Username = userName; actionLog.LogContent = string.Format("Update Salesperson,ID:{0},SaleName:{1} ", sales.Id, sales.SaleName); ActionLogBLL ab = new ActionLogBLL(); ab.Create(actionLog); return(new SaveResult(true)); }
static void Main() { var salesperson1 = new Salesperson("Salesperson 1"); var salesperson2 = new Salesperson("Salesperson 2"); var salesperson3 = new Salesperson("Salesperson 3"); salesperson1.AddProducts(new Product[] { new Product1(), new Product1(), new Product1(), new Product2(), new Product3(), new Product3(), new Product4() }); salesperson2.AddProducts(new Product[] { new Product1(), new Product1(), new Product2(), new Product2(), new Product2(), new Product2(), new Product3(), new Product3(), new Product4(), new Product5(), new Product5(), new Product5() }); salesperson3.AddProducts(new Product[] { new Product1(), new Product1(), new Product4(), new Product4(), new Product4(), new Product5() }); Console.WriteLine(salesperson1); Console.WriteLine(salesperson2); Console.WriteLine(salesperson3); }
public ActionResult Create(Salesperson newPerson) { var nextId = _db.Salespersons.Max(x => x.Id); newPerson.Id = nextId + 1; try { if (ModelState.IsValid) { //Check if Sales person already exists var existingSalesperson = (from p in _db.Salespersons where p.First_Name == newPerson.First_Name && p.Last_Name == newPerson.Last_Name select p).Count(); if (existingSalesperson > 0) { ModelState.AddModelError("", "This Salesperson Already Exists"); return(View()); } else { _db.Salespersons.Add(newPerson); _db.SaveChanges(); } } return(RedirectToAction("Index")); } catch { return(View()); } }
public List <Salesperson> List() { using (var con = new SqlConnection(_connectionString)) { string Command = "SELECT * FROM Salesperson"; var cmd = new SqlCommand(Command, con); con.Open(); var salespersonList = new List <Salesperson>(); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.HasRows) { while (reader.Read()) { var salesperson = new Salesperson(); salesperson.SPId = reader.GetInt32(0); salesperson.Firstname = reader.GetString(1); salesperson.Lastname = reader.GetString(2); salesperson.Description = reader.GetString(3); salespersonList.Add(salesperson); } reader.NextResult(); } } return(salespersonList); } }
// POST: api/Salesperson public Salesperson Post([FromBody] Salesperson value) { if (value != null) { var faulted = new Salesperson(); faulted.IsFaulted = false; try { db.Persist(value); return(faulted); } catch (DatabaseLink.DataLayerArgumentException e) { faulted.IsFaulted = true; faulted.DataLayerArgumentException = e.Message; } catch (DatabaseLink.DataLayerException e) { faulted.IsFaulted = true; faulted.DataLayerException = e.Message; } return(faulted); } return(null); }
public void SalespersonControllerTest_Post_Delete() { Task.Run(async() => { var person = new Salesperson() { Name = "Kyle", LastName = "Matthews" }; var p = await controller.GetAllAsync(); int countOld = p.Count(); await controller.PersistAsync(person); p = await controller.GetAllAsync(); int countNew = p.Count(); Assert.AreNotEqual(countOld, countNew); int id = p.ToList().SingleOrDefault(x => { return(x.Name.Equals(person.Name) && x.LastName.Equals(person.LastName)); }).Id; await controller.DeleteAsync(id); p = await controller.GetAllAsync(); countNew = p.Count(); Assert.AreEqual(countOld, countNew); }).GetAwaiter().GetResult(); }
public async Task <IActionResult> PutSalesperson([FromRoute] int id, [FromBody] Salesperson salesperson) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != salesperson.SalespersonId) { return(BadRequest()); } _context.Entry(salesperson).State = EntityState.Modified; try { await _context.SaveChangesAsync(); return(Ok(salesperson)); } catch (DbUpdateConcurrencyException) { if (!SalespersonExists(id)) { return(NotFound()); } else { throw; } } }
// PUT: api/Salespersons/5 public async Task <IHttpActionResult> Put(int id, [FromBody] Salesperson person, CancellationToken ct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != person.SalespersonId) { return(BadRequest()); } try { await _service.Update(person, ct); } catch { if (!SalespersonExists(id)) { return(NotFound()); } } return(StatusCode(HttpStatusCode.NoContent)); }
//Update Salesperson to Database private bool UpdateSalesperson() { bool updated = true; Salesperson salesperson = new Salesperson(); salesperson.SalespersonID = Convert.ToInt32(dgvSalesperson.SelectedRows[0].Cells[0].Value.ToString()); salesperson.Name = tbxSalespersonName.Text; salesperson.Surname = tbxSalespersonSurname.Text; salesperson.Username = tbxUsername.Text; salesperson.Password = EncryptionHelper.Encrypt(tbxPassword.Text); salesperson.Privileges = cmbPrivileges.Text; salesperson.EmployeeType = cmbEmployeeType.Text; try { handlerSalesperson.UpdateSalesperson(salesperson); } catch (Exception ex) { updated = false; MessageBox.Show("Error occured when updating salesperson!" + Environment.NewLine + Environment.NewLine + ex.Message); } return(updated); }
public IActionResult Put(int id, [FromBody] Salesperson value) { var Salesperson = SalespersonItems.Find(id); SalespersonItems.Update(value); return(new NoContentResult()); }
public async Task MoveSalesPersonWithoutGroupToExistingGroupMoq() { var srMock = new Mock <ISalesPersonRepository>(); var sgrMock = new Mock <ITrackingRepository <SalesGroup> >(); var salesperson = new Salesperson() { Id = 1 }; sgrMock.Setup(x => x.GetByID(1)).Returns(Task.FromResult(new SalesGroup() { Id = 1, State = "TEST" })); srMock.Setup(x => x.GetByID(1)).Returns(Task.FromResult(salesperson)); srMock.Setup(x => x.Save(It.IsAny <Salesperson>())).Callback <Salesperson>(p => salesperson = p); var service = new SalesPersonService(srMock.Object, sgrMock.Object); await service.MoveSalesPersonToGroup(1, 1); var person = await srMock.Object.GetByID(1); Assert.IsTrue(person.SalesGroup.State == "TEST"); }
//Add Salesperson to Database private bool AddSalesperson() { bool added = true; Salesperson salesperson = new Salesperson(); salesperson.Name = tbxSalespersonName.Text; salesperson.Surname = tbxSalespersonSurname.Text; salesperson.Username = tbxUsername.Text; salesperson.Password = EncryptionHelper.Encrypt(tbxPassword.Text); salesperson.Privileges = cmbPrivileges.Text; salesperson.EmployeeType = cmbEmployeeType.Text; try { handlerSalesperson.AddSalesperson(salesperson); } catch (Exception ex) { added = false; MessageBox.Show("Error occured when adding salesperson!" + Environment.NewLine + Environment.NewLine + ex.Message); } return(added); }
public async Task <IActionResult> PutSalesperson([FromRoute] int id, [FromBody] Salesperson salesperson) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != salesperson.SalespersonId) { return(BadRequest()); } try { await _salespeople.Update(salesperson); return(Ok(salesperson)); } catch (DbUpdateConcurrencyException) { if (!await SalespersonExists(id)) { return(NotFound()); } else { return(BadRequest()); } } }
public async Task <IActionResult> PostSalesperson([FromBody] Salesperson salesperson) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { await _salespeople.Add(salesperson); } catch (DbUpdateException) { if (!await SalespersonExists(salesperson.SalespersonId)) { return(NotFound()); } else { return(BadRequest()); } } return(CreatedAtAction("GetSalesperson", new { id = salesperson.SalespersonId }, salesperson)); }
public async Task <ActionResult <Salesperson> > PostSalesperson(Salesperson salesperson) { _context.Salespeople.Add(salesperson); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSalesperson", new { id = salesperson.Id }, salesperson)); }
public async Task <IActionResult> PutSalesperson(int id, Salesperson salesperson) { if (id != salesperson.Id) { return(BadRequest()); } _context.Entry(salesperson).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SalespersonExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public Salesperson Get(int id) { using (var con = new SqlConnection(_connectionString)) { string Command = "SELECT * from Salesperson where SPId = @id"; var cmd = new SqlCommand(Command, con); cmd.Parameters.AddWithValue("@id", id); con.Open(); var salesperson = new Salesperson(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { salesperson.SPId = reader.GetInt32(0); salesperson.Firstname = reader.GetString(1); salesperson.Lastname = reader.GetString(2); salesperson.Description = reader.GetString(3); } } } return(salesperson); } }
public async Task <Salesperson> Update(Salesperson salesperson) { _context.Salesperson.Update(salesperson); await _context.SaveChangesAsync(); return(salesperson); }
public void UpdateSalesperson(Salesperson salesperson) { using (SalesDB db = new SalesDB()) { db.Entry(salesperson).State = EntityState.Modified; db.SaveChanges(); } }
public void AddSalesperson(Salesperson salesperson) { using (SalesDB db = new SalesDB()) { db.Salespersons.Add(salesperson); db.SaveChanges(); } }
public async Task <Salesperson> Add(Salesperson salesperson) { await _context.Salesperson.AddAsync(salesperson); await _context.SaveChangesAsync(); return(salesperson); }
public Salesperson Remove(int id) { Salesperson item = context.Salesperson.SingleOrDefault(s => s.SalespersonId == id); context.Salesperson.Remove(item); context.SaveChanges(); return(item); }
public ActionResult DeleteConfirmed(int id) { Salesperson salesperson = db.Salespeople.Find(id); db.Salespeople.Remove(salesperson); db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Put(int id, [FromBody] Salesperson value) { var salePerson = saleRepository.Find(id); saleRepository.Update(value); return(new NoContentResult()); }