public ActionResult Index() { List <Client> clients = null; List <ClientAddress> addresses = null; using (var ctx = new ResuestServiceContext()) { clients = ctx.Clients.ToList(); addresses = ctx.ClientAddresses.ToList(); } var clientsWithAddresQuery = from c in clients join a in addresses on c.Symbol equals a.ClientSymbol select new ClientWithAddressModel { Symbol = c.Symbol, Name = c.Name, Email = c.Email, PhoneNumber = c.PhoneNumber, Description = c.Description, Street = a.Street, Number = a.Number, ZipCode = a.ZipCode, City = a.City }; var clientsWithAddres = clientsWithAddresQuery.ToList(); return(View(clientsWithAddres)); }
public ActionResult Adding(ClientWithAddressModel clientWithAddres) { var client = new Client { Symbol = clientWithAddres.Symbol, Name = clientWithAddres.Name, Email = clientWithAddres.Email, PhoneNumber = clientWithAddres.PhoneNumber, Description = clientWithAddres.Description }; var clientAddress = new ClientAddress { ClientSymbol = clientWithAddres.Symbol, Street = clientWithAddres.Street, Number = clientWithAddres.Number, ZipCode = clientWithAddres.ZipCode, City = clientWithAddres.City }; using (var ctx = new ResuestServiceContext()) { ctx.Clients.Add(client); ctx.ClientAddresses.Add(clientAddress); ctx.SaveChanges(); } return(RedirectToAction("Index", "Clients")); }
public ActionResult Edit(string symbol) { Client client = null; ClientAddress address = null; using (var ctx = new ResuestServiceContext()) { client = ctx.Clients.SingleOrDefault(x => x.Symbol == symbol); address = ctx.ClientAddresses.SingleOrDefault(x => x.ClientSymbol == symbol); } var clientWithAddress = new ClientWithAddressModel { Symbol = client.Symbol, Name = client.Name, Email = client.Email, PhoneNumber = client.PhoneNumber, Description = client.Description, Street = address.Street, Number = address.Number, ZipCode = address.ZipCode, City = address.City }; return(View(clientWithAddress)); }
public ActionResult Preview(Guid id) { RequestPreviewModel request = null; using (var ctx = new ResuestServiceContext()) { request = ctx.Requests .Join(ctx.Clients, r => r.ClientSymbol, c => c.Symbol, (r, c) => new RequestPreviewModel { Id = r.Id, ClientSymbol = c.Symbol, RequestPriority = r.RequestPriority, RequestType = r.RequestType, Description = r.Description }).SingleOrDefault(r => r.Id == id); request.Employees = ctx.EmployeeRequests .Join(ctx.Employees, er => er.EmployeeIdentifier, r => r.Identifier, (er, r) => new { RequestId = er.RequestId, Identifier = r.Identifier, FirstName = r.FirstName, LastName = r.LastName }).Where(er => er.RequestId == id).Select(er => new EmployeeModel { Identifier = er.Identifier, FirstName = er.FirstName, LastName = er.LastName }).ToList(); } return(View(request)); }
public ActionResult Closing(Guid id) { using (var ctx = new ResuestServiceContext()) { var request = ctx.Requests.SingleOrDefault(r => r.Id == id); request.RequestStatus = RequestStatus.Zamkniety; request.ResolveDate = DateTime.Now; ctx.SaveChanges(); } return(RedirectToAction("Index", "Requests")); }
public ActionResult Index() { List<EmployeeModel> employees = null; using (var ctx = new ResuestServiceContext()) { employees = ctx.Employees.Select(x => new EmployeeModel { Identifier = x.Identifier, FirstName = x.FirstName, LastName = x.LastName }).ToList(); } return View(employees); }
public ActionResult Editing(EmployeeModel employeeModel) { if (!ModelState.IsValid) { return(Edit(employeeModel)); } using (var ctx = new ResuestServiceContext()) { var employee = ctx.Employees.SingleOrDefault(x => x.Identifier == employeeModel.Identifier); employee.FirstName = employeeModel.FirstName; employee.LastName = employeeModel.LastName; ctx.SaveChanges(); } return(RedirectToAction("Index", "Employees")); }
public ActionResult Assigning(RequestEmployeesModel requestEmployeesModel) { using (var ctx = new ResuestServiceContext()) { var employeesToRemove = ctx.EmployeeRequests.Where(e => e.RequestId == requestEmployeesModel.RequestId).AsEnumerable(); ctx.EmployeeRequests.RemoveRange(employeesToRemove); var employeeRequests = requestEmployeesModel.Employees.Where(e => e.IsAssigned).Select(e => new EmployeeRequest { RequestId = requestEmployeesModel.RequestId, EmployeeIdentifier = e.Identifier }); ctx.EmployeeRequests.AddRange(employeeRequests); ctx.SaveChanges(); } return(RedirectToAction("Index", "Requests")); }
public ActionResult Edit(Guid identifier) { Employee employee = null; using (var ctx = new ResuestServiceContext()) { employee = ctx.Employees.SingleOrDefault(x => x.Identifier == identifier); } var employeeModel = new EmployeeModel { Identifier = employee.Identifier, FirstName = employee.FirstName, LastName = employee.LastName }; return(View(employeeModel)); }
public ActionResult Editing(ClientWithAddressModel clientWithAddres) { using (var ctx = new ResuestServiceContext()) { var client = ctx.Clients.SingleOrDefault(x => x.Symbol == clientWithAddres.Symbol); var address = ctx.ClientAddresses.SingleOrDefault(x => x.ClientSymbol == clientWithAddres.Symbol); client.Name = clientWithAddres.Name; client.Email = clientWithAddres.Email; client.PhoneNumber = clientWithAddres.PhoneNumber; client.Description = clientWithAddres.Description; address.Street = clientWithAddres.Street; address.Number = clientWithAddres.Number; address.ZipCode = clientWithAddres.ZipCode; address.City = clientWithAddres.City; ctx.SaveChanges(); } return(RedirectToAction("Index", "Clients")); }
public ActionResult Index() { List <RequestForListModel> requests = null; using (var ctx = new ResuestServiceContext()) { requests = ctx.Requests .Join(ctx.Clients, r => r.ClientSymbol, c => c.Symbol, (r, c) => new RequestForListModel { Identifier = r.Id, ClientName = c.Name, Date = r.Date, RequestPriority = r.RequestPriority, RequestType = r.RequestType, RequestStatus = r.RequestStatus, ResolveDate = r.ResolveDate }).ToList(); } return(View(requests)); }
public ActionResult Adding(RequestAddModel requestModel) { var request = new Request { Id = Guid.NewGuid(), ClientSymbol = requestModel.ClientSymbol, Description = requestModel.Description, RequestPriority = requestModel.RequestPriority, RequestType = requestModel.RequestType, RequestStatus = RequestStatus.Nowy, Date = DateTime.Now, }; using (var ctx = new ResuestServiceContext()) { ctx.Requests.Add(request); ctx.SaveChanges(); } return(RedirectToAction("Index", "Requests")); }
public ActionResult Adding(EmployeeModel employeeModel) { if (!ModelState.IsValid) { return(Add(employeeModel)); } var employee = new Employee { Identifier = Guid.NewGuid(), FirstName = employeeModel.FirstName, LastName = employeeModel.LastName }; using (var ctx = new ResuestServiceContext()) { ctx.Employees.Add(employee); ctx.SaveChanges(); } return(RedirectToAction("Index", "Employees")); }
public ActionResult Assign(Guid id) { List <Employee> employees = null; using (var ctx = new ResuestServiceContext()) { employees = ctx.Employees.ToList(); } var requestEmployees = new RequestEmployeesModel { RequestId = id, Employees = employees.ToList().Select(e => new EmployeeModel { Identifier = e.Identifier, FirstName = e.FirstName, LastName = e.LastName }).ToList() }; return(View(requestEmployees)); }