public async Task <TaskResult <DepartmentsDto> > UpdateAsync(DepartmentsDto departmentDto) { var department = new Departments { Active = departmentDto.Active, CreatedAt = departmentDto.CreatedAt, Id = departmentDto.Id, Name = departmentDto.Name, UpdatedAt = departmentDto.UpdatedAt, Description = departmentDto.Description }; var result = new TaskResult <DepartmentsDto>(); try { _context.Departments.Add(department); _context.Entry(department).State = System.Data.Entity.EntityState.Modified; await _context.SaveChangesAsync(); result.Data = departmentDto; result.Message = "El registro fue actualizado correctamente"; } catch (Exception e) { result.Success = false; result.Message = $"Error al intentar actualizar información del departamentos: {e.Message}"; } return(result); }
public async Task <TaskResult <DepartmentsDto> > SaveAsync(DepartmentsDto DepartmentsDto) { var department = new Departments { Active = DepartmentsDto.Active, CreatedAt = DepartmentsDto.CreatedAt, Id = DepartmentsDto.Id, Name = DepartmentsDto.Name, UpdatedAt = DepartmentsDto.UpdatedAt, Description = DepartmentsDto.Description }; var result = new TaskResult <DepartmentsDto>(); try { _context.Departments.Add(department); await _context.SaveChangesAsync(); result.Message = $"Se agregó el departamento {department.Name}"; } catch (Exception e) { result.Success = false; result.Message = $"Error al intentar agregar al departamento: {e.Message}"; } return(result); }
// GET: Contacts/Details/{key} public ActionResult Details(int id) { ShowContact ViewModel = new ShowContact(); //Pass along to the view information about who is logged in ViewModel.isadmin = User.IsInRole("Admin"); string url = "contactsdata/findcontact/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { //Put data into contact data transfer object ContactDto SelectedContact = response.Content.ReadAsAsync <ContactDto>().Result; ViewModel.contact = SelectedContact; url = "contactsdata/finddepartmentforcontact/" + id; response = client.GetAsync(url).Result; DepartmentsDto SelectedDepartment = response.Content.ReadAsAsync <DepartmentsDto>().Result; ViewModel.departments = SelectedDepartment; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
/// <summary> /// Displays the details of the department including the testimonials for the department /// </summary> /// <param name="Id">Id of the department</param> /// <returns> /// If successfull in fetching the data from the api controller, returns a "DepartmentDetails" View Model /// which contains information on the details of the department and the testimonials of the department. /// </returns> /// <example> /// GET: Department/DetailsofDepartment/5 /// </example> public ActionResult DetailsofDepartment(int Id) { DepartmentDetails departmentdetails = new DepartmentDetails(); departmentdetails.isadmin = User.IsInRole("admin"); departmentdetails.isloggedinUser = User.IsInRole("user"); departmentdetails.userid = User.Identity.GetUserId(); string url = "DepartmentData/FindDepartment/" + Id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { DepartmentsDto department = response.Content.ReadAsAsync <DepartmentsDto>().Result; departmentdetails.DepartmentDto = department; url = "DepartmentData/FindTestimonialsForDepartment/" + Id; response = client.GetAsync(url).Result; IEnumerable <TestimonialDto> testimonials = response.Content.ReadAsAsync <IEnumerable <TestimonialDto> >().Result; departmentdetails.Testimonials = testimonials; url = "DepartmentData/FindJobPostingsforDepartment/" + Id; response = client.GetAsync(url).Result; IEnumerable <JobPostingsModel> jobPostings = response.Content.ReadAsAsync <IEnumerable <JobPostingsModel> >().Result; departmentdetails.JobPostings = jobPostings; return(View(departmentdetails)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult FindDepartmentForContact(int id) { //Finds the first department which has any contacts //that match the input contactid DepartmentsModel departments = db.Departments .Where(d => d.Contact.Any(c => c.contact_id == id)) .FirstOrDefault(); //if not found, return 404 status code. if (departments == null) { return(NotFound()); } //put into a 'friendly object format' DepartmentsDto DepartmentsDtos = new DepartmentsDto { DepartmentId = departments.DepartmentId, DepartmentName = departments.DepartmentName }; //pass along data as 200 status code OK response return(Ok(DepartmentsDtos)); }
public async Task <ActionResult> Create(DepartmentsDto Data) { if (!ModelState.IsValid) { return(View()); } var newModel = await _departmentsRepository.SaveAsync(Data); return(View(newModel)); }
public HttpResponseMessage AddNewDepartment(DepartmentsDto department) { var repository = new DepartmentsRepository(); var result = repository.Create(department); if (result) { return(Request.CreateResponse(HttpStatusCode.Created)); } return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Could not add new department")); }
public HttpResponseMessage CreateDepartment(DepartmentsDto department) { var repo = new DepartmentsRepository(); var newDepartment = repo.CreateDepartment(department); if (newDepartment) { return(Request.CreateResponse(HttpStatusCode.Created)); } return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Sorry, your new department cannot be created at this time.")); }
public async Task <ActionResult> Edit(DepartmentsDto Data) { if (!ModelState.IsValid) { return(View(new TaskResult <DepartmentsDto> { Data = Data })); } var model = await _departmentsRepository.UpdateAsync(Data); return(View(model)); }
public bool Create(DepartmentsDto department) { using (var db = GetConnection()) { db.Open(); var records = db.Execute(@"INSERT INTO [dbo].[Department] ([Name] ,[Budget]) VALUES (@Name ,@Budget)", department); return(records == 1); } }
public bool CreateDepartment(DepartmentsDto department) { using (var db = CreateConnection()) { db.Open(); var createDepartment = db.Execute(@"INSERT INTO [dbo].[Departments] ([DepartmentName]) VALUES (@DepartmentName)", department); return(createDepartment == 1); } }
public ActionResult DeleteConfirm(int id) { string url = "DepartmentData/FindDepartment/" + id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { DepartmentsDto Department = response.Content.ReadAsAsync <DepartmentsDto>().Result; return(View(Department)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult FindDepartment(int id) { DepartmentsModel Department = db.Departments.Find(id); if (Department == null) { return(NotFound()); } DepartmentsDto NewDepartment = new DepartmentsDto { DepartmentId = Department.DepartmentId, DepartmentName = Department.DepartmentName }; return(Ok(NewDepartment)); }
public ActionResult Update(int id) { GetApplicationCookie(); string url = "DepartmentData/FindDepartment/" + id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { DepartmentsDto UpdatedDepartment = response.Content.ReadAsAsync <DepartmentsDto>().Result; return(View(UpdatedDepartment)); } else { return(RedirectToAction("Error")); } }
public async Task <Response <DepartmentsDto> > GetDepartments(DepartmentsQuery request) { var result = _context.Departments.AsQueryable(); if (!string.IsNullOrEmpty(request.Name)) { result = result.Where(x => x.Name.Contains(request.Name)); } ///pagenating int take = request.PageSize; int skip = (request.PageId - 1) * take; int totalPages = (int)Math.Ceiling(result.Count() / (double)take); var finalResult = result.OrderBy(x => x.Name).Skip(skip).Take(take).AsQueryable(); //---------------- var resultData = new DepartmentsDto { Dtos = await finalResult.Select(d => new DepartmentDto() { Id = d.Id, Name = d.Name }).ToListAsync(), PageId = request.PageId, PageSize = request.PageSize, Total = await result.CountAsync() }; return(new Response <DepartmentsDto> { Data = resultData, Status = true, Message = "success" }); }
public IHttpActionResult getdepartmentspage(int StartIndex, int PerPage) { List <DepartmentsModel> Departments = db.Departments.OrderBy(d => d.DepartmentId).Skip(StartIndex).Take(PerPage).ToList(); List <DepartmentsDto> DepartmentDtos = new List <DepartmentsDto> { }; //Here you can choose which information is exposed to the API foreach (var Department in Departments) { DepartmentsDto NewDepartment = new DepartmentsDto { DepartmentId = Department.DepartmentId, DepartmentName = Department.DepartmentName }; DepartmentDtos.Add(NewDepartment); } return(Ok(DepartmentDtos)); }
public IHttpActionResult GetDepartments() { IEnumerable <DepartmentsModel> Departments = db.Departments.ToList(); List <DepartmentsDto> DepartmentsDtos = new List <DepartmentsDto> { }; //Here you can choose which information is exposed to the API foreach (var department in Departments) { DepartmentsDto NewDepartments = new DepartmentsDto { DepartmentId = department.DepartmentId, DepartmentName = department.DepartmentName }; DepartmentsDtos.Add(NewDepartments); } return(Ok(DepartmentsDtos)); }
public IHttpActionResult ListDepartments() { List <DepartmentsModel> Departments = db.Departments.ToList(); List <DepartmentsDto> DepartmentDtos = new List <DepartmentsDto> { }; foreach (var Department in Departments) { DepartmentsDto NewDepartment = new DepartmentsDto { DepartmentId = Department.DepartmentId, DepartmentName = Department.DepartmentName }; DepartmentDtos.Add(NewDepartment); } return(Ok(DepartmentDtos)); }
/// <summary> /// Displays the details of the department including the testimonials for the department /// </summary> /// <param name="Id">Id of the department</param> /// <returns> /// If successfull in fetching the data from the api controller, returns a "DepartmentDetails" View Model /// which contains information on the details of the department and the testimonials of the department. /// </returns> /// <example> /// GET: Department/DetailsofDepartment/5 /// </example> public ActionResult DetailsofDepartment(int Id) { DepartmentDetails departmentdetails = new DepartmentDetails(); string url = "DepartmentData/FindDepartment/" + Id; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { DepartmentsDto department = response.Content.ReadAsAsync <DepartmentsDto>().Result; departmentdetails.DepartmentDto = department; url = "DepartmentData/FindTestimonialsForDepartment/" + Id; response = client.GetAsync(url).Result; IEnumerable <TestimonialDto> testimonials = response.Content.ReadAsAsync <IEnumerable <TestimonialDto> >().Result; departmentdetails.Testimonials = testimonials; return(View(departmentdetails)); } else { return(RedirectToAction("Error")); } }
public IHttpActionResult FindDepartmentForEcard(int id) { DepartmentsModel departments = db.Departments .Where(d => d.Ecards.Any(e => e.ecard_id == id)) .FirstOrDefault(); //if not found, return 404 status code. if (departments == null) { return(NotFound()); } //put into a 'friendly object format' DepartmentsDto DepartmentsDtos = new DepartmentsDto { DepartmentId = departments.DepartmentId, DepartmentName = departments.DepartmentName }; //pass along data as 200 status code OK response return(Ok(DepartmentsDtos)); }
public ActionResult DeleteConfirm(int DepartmentId, int TestimonialId) { TestimonialDetails Testimonial_Details = new TestimonialDetails(); string url = "TestimonialData/FindTestimonial/" + TestimonialId; HttpResponseMessage response = client.GetAsync(url).Result; if (response.IsSuccessStatusCode) { TestimonialDto Testimonial = response.Content.ReadAsAsync <TestimonialDto>().Result; Testimonial_Details.TestimonialDto = Testimonial; url = "DepartmentData/FindDepartment/" + DepartmentId; response = client.GetAsync(url).Result; DepartmentsDto Department = response.Content.ReadAsAsync <DepartmentsDto>().Result; Testimonial_Details.DepartmentDto = Department; return(View(Testimonial_Details)); } else { return(RedirectToAction("Error")); } }
public async Task <TaskResult <List <UsersDto> > > GetAllAsync(ApplicationUserManager userManager) { List <UsersDto> costumersDtos = new List <UsersDto>(); var result = new TaskResult <List <UsersDto> >(); try { var customers = await _context .Users .Include(e => e.Department) .Where(e => e.Deleted == false).ToListAsync(); customers.ForEach((customer) => { var departmentDto = new DepartmentsDto(); if (customer.Department != null) { departmentDto = new DepartmentsDto { Id = customer.Department.Id, Active = customer.Department.Active, CreatedAt = customer.Department.CreatedAt, Description = customer.Department.Description, Name = customer.Department.Name, DeletedAt = customer.Department.DeletedAt, Deleted = customer.Department.Deleted, UpdatedAt = customer.Department.UpdatedAt }; } costumersDtos.Add( new UsersDto { Active = customer.Active, CreatedAt = customer.CreatedAt, Email = customer.Email, Id = customer.Id, LastName = customer.LastName, Name = customer.Name, UpdatedAt = customer.UpdatedAt, PhoneNumber = customer.PhoneNumber, DocumentNumber = customer.DocumentNumber, Department = departmentDto }); }); foreach (var customer in costumersDtos) { var roleNames = await userManager.GetRolesAsync(customer.Id); var roleName = roleNames.Count > 0 ? roleNames[0] : "N/A"; customer.RoleName = roleName; } result.Data = costumersDtos; } catch (Exception e) { result.Success = false; result.Message = $"Error al recuperar el listado de clientes: {e.Message}"; } return(result); }