public static EmployeeDocumentDTO EmplyeeFamilyDbToDTO(EmployeeDocument ModelData) { EmployeeDocumentDTO Record = new EmployeeDocumentDTO { DocumentCatId = ModelData.DocumentCatId, DocumentCreatedAt = ModelData.DocumentCreatedAt, DocumentEmpCode = ModelData.DocumentEmpCode, DocumentId = ModelData.DocumentId, DocumentOnlyAdmin = ModelData.DocumentOnlyAdmin, DocumentRemarks = ModelData.DocumentRemarks, DocumentTitle = ModelData.DocumentTitle, DocumentVerified = ModelData.DocumentVerified, Employee = new EmployeeDTO { EmpCode = ModelData.Employee.EmpCode, EmpName = ModelData.Employee.EmpName, } }; return(Record); }
public async Task <IActionResult> Delete([FromBody] EmployeeDocument _EmployeeDocument) { EmployeeDocument _EmployeeDocumentq = new EmployeeDocument(); try { _EmployeeDocumentq = _context.EmployeeDocument .Where(x => x.EmployeeDocumentId == (Int64)_EmployeeDocument.EmployeeDocumentId) .FirstOrDefault(); _context.EmployeeDocument.Remove(_EmployeeDocumentq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}"))); } return(await Task.Run(() => Ok(_EmployeeDocumentq))); }
public ActionResult Edit(decimal id, EmployeeDocument employeeDocument) { try { if (ModelState.IsValid) { EmployeeDocument obj = EmployeeDocument.Find(id); if (obj != null) { obj = employeeDocument; if (obj.EmpDoc_FileUpload != null) { string oldfileName = Server.MapPath(obj.EmpDoc_File); string fileName = DateTime.Now.ToString("ddMMyyyyhhmmsstt") + "_" + Path.GetFileName(obj.EmpDoc_FileUpload.FileName); fileName = Regex.Replace(fileName, "[^a-zA-Z0-9_.]+", "", RegexOptions.Compiled); string path = Path.Combine(Server.MapPath("~/Uploads/Documents"), fileName); obj.EmpDoc_FileUpload.SaveAs(path); obj.EmpDoc_File = "~/Uploads/Documents/" + fileName; if (System.IO.File.Exists(oldfileName)) { System.IO.File.Delete(oldfileName); } } EmployeeDocument.Update(obj); ViewBag.Message = "Employee Document Updated Successfully"; } return(RedirectToAction("Index")); } else { return(View()); } } catch (Exception ex) { return(View()); } }
public ActionResult DeleteByEmployee(decimal id) { try { //EmployeeDocument.DeleteByEmployee(id); List <EmployeeDocument> list = EmployeeDocument.FindByEmployee(id); foreach (EmployeeDocument obj in list) { EmployeeDocument.Delete(obj.EmpDoc_Id); string oldfileName = Server.MapPath(obj.EmpDoc_File); if (System.IO.File.Exists(oldfileName)) { System.IO.File.Delete(oldfileName); } } ViewBag.Message = "Employee Document(s) Deleted Successfully"; return(RedirectToAction("Index")); } catch (Exception ex) { return(View()); } }
public async Task <ActionResult <EmployeeDocument> > Update([FromBody] EmployeeDocument _EmployeeDocument) { EmployeeDocument _EmployeeDocumentq = _EmployeeDocument; try { _EmployeeDocumentq = await(from c in _context.EmployeeDocument .Where(q => q.EmployeeDocumentId == _EmployeeDocument.EmployeeDocumentId) select c ).FirstOrDefaultAsync(); _context.Entry(_EmployeeDocumentq).CurrentValues.SetValues((_EmployeeDocument)); //_context.EmployeeDocument.Update(_EmployeeDocumentq); await _context.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError($"Ocurrio un error: { ex.ToString() }"); return(await Task.Run(() => BadRequest($"Ocurrio un error:{ex.Message}"))); } return(await Task.Run(() => Ok(_EmployeeDocumentq))); }
public ActionResult SaveEmployeeDocuments(EmployeeDocument employeedocument, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { string fileName = Path.GetFileNameWithoutExtension(file.FileName); string extension = Path.GetExtension(file.FileName); fileName = fileName + DateTime.Now.ToString("yymmdd") + extension; employeedocument.FilePath = "~/Image/" + fileName; fileName = Path.Combine(Server.MapPath("~/Image/"), fileName); file.SaveAs(Path.Combine(fileName)); employeedocument.FilePath = fileName; } using (EMSDbContext dc = new EMSDbContext()) { dc.EmployeeDocuments.Add(employeedocument); dc.SaveChanges(); } ModelState.Clear(); ViewBag.FileStatus = "File uploaded successfully."; } //if (ModelState.IsValid) //{ // db.EmployeeDocuments.Add(employeedocument); // db.SaveChanges(); // ViewBag.FileStatus = "File uploaded successfully."; //} //ModelState.Clear(); ViewBag.DocumentTypeId = new SelectList(db.DocumentTypes, "Id", "TypeName", employeedocument.DocumentTypeId); ViewBag.EmployeeId = new SelectList(db.Employees, "Id", "EmployeeRegNo", employeedocument.EmployeeId); return(View(employeedocument)); }
public static EmployeeDocument ConvertToEmployeeDocument(this EmployeeDocumentViewModel employeeDocumentViewModel) { EmployeeDocument EmployeeDocument = new EmployeeDocument() { Id = employeeDocumentViewModel.Id, Identifier = employeeDocumentViewModel.Identifier, EmployeeId = employeeDocumentViewModel.Employee?.Id ?? null, Name = employeeDocumentViewModel.Name, CreateDate = employeeDocumentViewModel.CreateDate, Path = employeeDocumentViewModel.Path, ItemStatus = employeeDocumentViewModel.ItemStatus, Active = employeeDocumentViewModel.IsActive, CreatedById = employeeDocumentViewModel.CreatedBy?.Id ?? null, CompanyId = employeeDocumentViewModel.Company?.Id ?? null, CreatedAt = employeeDocumentViewModel.CreatedAt, UpdatedAt = employeeDocumentViewModel.UpdatedAt }; return(EmployeeDocument); }
public static EmployeeDocumentViewModel ConvertToEmployeeDocumentViewModel(this EmployeeDocument employeeDocument) { EmployeeDocumentViewModel EmployeeDocumentViewModel = new EmployeeDocumentViewModel() { Id = employeeDocument.Id, Identifier = employeeDocument.Identifier, Employee = employeeDocument.Employee?.ConvertToEmployeeViewModelLite(), Name = employeeDocument.Name, CreateDate = employeeDocument.CreateDate, Path = employeeDocument.Path, ItemStatus = employeeDocument.ItemStatus, IsActive = employeeDocument.Active, CreatedBy = employeeDocument.CreatedBy?.ConvertToUserViewModelLite(), Company = employeeDocument.Company?.ConvertToCompanyViewModelLite(), UpdatedAt = employeeDocument.UpdatedAt, CreatedAt = employeeDocument.CreatedAt }; return(EmployeeDocumentViewModel); }
public EmployeeDocDlg(EmployeeDocument sub, IUnitOfWork uow, ICommonServices commonServices, bool canEditEmployee) : this(sub.Id, uow, commonServices, canEditEmployee) { }
public EmployeeDocDlg(EmployeeDocument sub, IUnitOfWork uow, ICommonServices commonServices) : this(sub.Id, uow, commonServices) { }
public EmployeeDocDlg(EmployeeDocument sub, IUnitOfWork uow) : this(sub.Id, uow) { }
public EmployeeDocumentDTO InsertEmployeeDocument(EmployeeDocumentDTO Record) { EmployeeDocument ReturnRecord = EmployeeDocumentRequestFormatter.ConvertRespondentInfoFromDTO(Record); return(EmployeeDocumentRequestFormatter.ConvertRespondentInfoToDTO(_unitOfWork.EmployeeDocumentRepository.Create(ReturnRecord))); }
public List <EmployeeDocument> GetEmployeeDocuments(int companyId) { List <EmployeeDocument> EmployeeDocuments = new List <EmployeeDocument>(); string queryString = "SELECT EmployeeDocumentId, EmployeeDocumentIdentifier, " + "EmployeeId, EmployeeIdentifier, EmployeeCode, EmployeeName, " + "Name, CreateDate, Path, ItemStatus, " + "Active, UpdatedAt, CreatedById, CreatedByFirstName, CreatedByLastName, " + "CompanyId, CompanyName " + "FROM vEmployeeDocuments " + "WHERE CompanyId = @CompanyId;"; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlCommand command = connection.CreateCommand(); command.CommandText = queryString; command.Parameters.Add(new SqlParameter("@CompanyId", companyId)); connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { EmployeeDocument employeeDocument; while (reader.Read()) { employeeDocument = new EmployeeDocument(); employeeDocument.Id = Int32.Parse(reader["EmployeeDocumentId"].ToString()); employeeDocument.Identifier = Guid.Parse(reader["EmployeeDocumentIdentifier"].ToString()); if (reader["EmployeeId"] != DBNull.Value) { employeeDocument.Employee = new Employee(); employeeDocument.EmployeeId = Int32.Parse(reader["EmployeeId"].ToString()); employeeDocument.Employee.Id = Int32.Parse(reader["EmployeeId"].ToString()); employeeDocument.Employee.Identifier = Guid.Parse(reader["EmployeeIdentifier"].ToString()); employeeDocument.Employee.Code = reader["EmployeeCode"].ToString(); employeeDocument.Employee.Name = reader["EmployeeName"].ToString(); } if (reader["Name"] != DBNull.Value) { employeeDocument.Name = reader["Name"].ToString(); } if (reader["CreateDate"] != DBNull.Value) { employeeDocument.CreateDate = DateTime.Parse(reader["CreateDate"].ToString()); } if (reader["Path"] != DBNull.Value) { employeeDocument.Path = reader["Path"].ToString(); } if (reader["ItemStatus"] != DBNull.Value) { employeeDocument.ItemStatus = Int32.Parse(reader["ItemStatus"].ToString()); } employeeDocument.Active = bool.Parse(reader["Active"].ToString()); employeeDocument.UpdatedAt = DateTime.Parse(reader["UpdatedAt"].ToString()); if (reader["CreatedById"] != DBNull.Value) { employeeDocument.CreatedBy = new User(); employeeDocument.CreatedById = Int32.Parse(reader["CreatedById"].ToString()); employeeDocument.CreatedBy.Id = Int32.Parse(reader["CreatedById"].ToString()); employeeDocument.CreatedBy.FirstName = reader["CreatedByFirstName"]?.ToString(); employeeDocument.CreatedBy.LastName = reader["CreatedByLastName"]?.ToString(); } if (reader["CompanyId"] != DBNull.Value) { employeeDocument.Company = new Company(); employeeDocument.CompanyId = Int32.Parse(reader["CompanyId"].ToString()); employeeDocument.Company.Id = Int32.Parse(reader["CompanyId"].ToString()); employeeDocument.Company.Name = reader["CompanyName"].ToString(); } EmployeeDocuments.Add(employeeDocument); } } } return(EmployeeDocuments); //List<EmployeeDocument> EmployeeDocuments = context.EmployeeDocuments // .Include(x => x.Employee) // .Include(x => x.Company) // .Include(x => x.CreatedBy) // .Where(x => x.Active == true && x.CompanyId == companyId) // .AsNoTracking() // .ToList(); //return EmployeeDocuments; }
public ActionResult List(decimal id) { ViewData["EmpId"] = id; return(View(EmployeeDocument.FindByEmployee(id))); }
public ActionResult Index() { return(View(EmployeeDocument.List())); }