private static void UpdateSummary(MongoDBContext dbContext, DateTime dateData, EmployeeWorkTimeLog employeeWorkTimeLog) { int month = dateData.Month; int year = dateData.Year; if (dateData.Day > 25) { // 26->31: chấm công tháng sau var nextMonthDate = dateData.AddMonths(1); month = nextMonthDate.Month; year = nextMonthDate.Year; } var existSum = dbContext.EmployeeWorkTimeMonthLogs.Find(m => m.EmployeeId.Equals(employeeWorkTimeLog.EmployeeId) && m.Year.Equals(year) && m.Month.Equals(month)).FirstOrDefault(); if (existSum != null) { // Do later //if (existSum.EnrollNumber != employeeWorkTimeLog.EnrollNumber){} var builderUpdateSum = Builders <EmployeeWorkTimeMonthLog> .Filter; var filterUpdateSum = builderUpdateSum.Eq(m => m.Id, existSum.Id); var updateSum = Builders <EmployeeWorkTimeMonthLog> .Update .Inc(m => m.Workday, employeeWorkTimeLog.WorkDay) .Inc(m => m.WorkTime, employeeWorkTimeLog.WorkTime.TotalMilliseconds) .Inc(m => m.Late, employeeWorkTimeLog.Late.TotalMilliseconds) .Inc(m => m.Early, employeeWorkTimeLog.Early.TotalMilliseconds) .Set(m => m.LastUpdated, dateData); dbContext.EmployeeWorkTimeMonthLogs.UpdateOne(filterUpdateSum, updateSum); } else { // Qui dinh 1 thang cho phep thiếu giờ (tre/sơm) 15p, // Qua 15 phut nếu ko có xác nhận công trừ 0.5 ngày var missingMinuteAllow = 15; var settingMissingMinuteAllow = dbContext.Settings.Find(m => m.Key.Equals("missingMinuteAllow")).FirstOrDefault(); if (settingMissingMinuteAllow != null && !string.IsNullOrEmpty(settingMissingMinuteAllow.Value)) { missingMinuteAllow = Convert.ToInt32(settingMissingMinuteAllow.Value); } //var lateMinuteAllow = 5; //var lateCountAllow = 1; //var earlyMinuteAllow = 5; //var earlyCountAllow = 1; //var settingLateMinuteAllow = dbContext.Settings.Find(m => m.Key.Equals("lateMinuteAllow")).FirstOrDefault(); //if (settingLateMinuteAllow != null && !string.IsNullOrEmpty(settingLateMinuteAllow.Value)) //{ // lateMinuteAllow = Convert.ToInt32(settingLateMinuteAllow.Value); //} //var settingLateCountAllow = dbContext.Settings.Find(m => m.Key.Equals("lateCountAllow")).FirstOrDefault(); //if (settingLateCountAllow != null && !string.IsNullOrEmpty(settingLateCountAllow.Value)) //{ // lateCountAllow = Convert.ToInt32(settingLateCountAllow.Value); //} //var settingEarlyMinuteAllow = dbContext.Settings.Find(m => m.Key.Equals("earlyMinuteAllow")).FirstOrDefault(); //if (settingEarlyMinuteAllow != null && !string.IsNullOrEmpty(settingEarlyMinuteAllow.Value)) //{ // earlyMinuteAllow = Convert.ToInt32(settingEarlyMinuteAllow.Value); //} //var settingEarlyCountAllow = dbContext.Settings.Find(m => m.Key.Equals("earlyCountAllow")).FirstOrDefault(); //if (settingEarlyCountAllow != null && !string.IsNullOrEmpty(settingEarlyCountAllow.Value)) //{ // earlyCountAllow = Convert.ToInt32(settingEarlyCountAllow.Value); //} dbContext.EmployeeWorkTimeMonthLogs.InsertOne(new EmployeeWorkTimeMonthLog { EmployeeId = employeeWorkTimeLog.EmployeeId, //EnrollNumber = employeeWorkTimeLog.EnrollNumber, Month = month, Year = year, Workday = employeeWorkTimeLog.WorkDay, WorkTime = employeeWorkTimeLog.WorkTime.TotalMilliseconds, Late = employeeWorkTimeLog.Late.TotalMilliseconds, Early = employeeWorkTimeLog.Early.TotalMilliseconds, LateApprove = 0, EarlyApprove = 0, MissingMinuteAllow = missingMinuteAllow, //LateCountAllow = 0, //LateMinuteAllow = lateMinuteAllow, //LateCountAllowUsed = 0, //LateCount = 0, //EarlyCountAllow = earlyCountAllow, //EarlyMinuteAllow = earlyMinuteAllow, //EarlyCountAllowUsed = 0, //EarlyCount = 0, LastUpdated = dateData }); } }
public static void DeleteFundInvestmentCollection() { MongoDBContext _client = new MongoDBContext(_settings.MongoDBConnectionString); _client.RemoveCollection(FUND_INVESTMENTS_COLLECTION); }
public HttpLogService(MongoDBContext mongoDBContext, IException_Service exceptionService) { _mongoDBContext = mongoDBContext; _exceptionService = exceptionService; }
public JsonResult Consultar(string fechaDesde, string fechaHasta, string tipoReporte, string idObjeto) { DateTime fDesde = Convert.ToDateTime(fechaDesde); DateTime fHasta = DateTime.Now; if (!String.IsNullOrEmpty(fechaHasta)) { fHasta = Convert.ToDateTime(fechaHasta); } decimal consumo = 0; switch (tipoReporte.ToLower()) { case "hogar": consumo = Reporte.consumoPorHogarYPeriodo(Convert.ToInt32(idObjeto), fDesde, fHasta); dBContext = new MongoDBContext(); reporteClienteColeccion = dBContext.database.GetCollection <ReporteCliente>("clientePorPeriodo"); int busquedaHistoricoHogar = 0; busquedaHistoricoHogar = (from t in reporteClienteColeccion.AsQueryable <ReporteCliente>() where t.IdUsuario == idObjeto && t.FechaDesde == fDesde.ToShortDateString() && (t.FechaHasta == fHasta.ToShortDateString() || t.FechaHasta == DateTime.Now.ToShortDateString()) && t.Consumo == consumo select t).Count(); if (busquedaHistoricoHogar == 0) { reporteCliente.IdUsuario = idObjeto; reporteCliente.FechaDesde = fDesde.ToShortDateString(); reporteCliente.FechaHasta = fHasta.ToShortDateString(); reporteCliente.Consumo = consumo; reporteClienteColeccion.InsertOne(reporteCliente); } break; case "tiposdisp": consumo = Reporte.consumoPorTipoDeDispositivoPorPeriodo(idObjeto, fDesde, fHasta); dBContext = new MongoDBContext(); reporteDispositivoColeccion = dBContext.database.GetCollection <ReporteDispositivo>("dispositivoPorPeriodo"); int busquedaHistoricoDispo = 0; busquedaHistoricoDispo = (from t in reporteDispositivoColeccion.AsQueryable <ReporteDispositivo>() where t.Tipo == idObjeto && t.FechaDesde == fDesde.ToShortDateString() && (t.FechaHasta == fHasta.ToShortDateString() || t.FechaHasta == DateTime.Now.ToShortDateString()) && t.Consumo == consumo select t).Count(); if (busquedaHistoricoDispo == 0) { reporteDispositivo.Tipo = idObjeto; reporteDispositivo.FechaDesde = fDesde.ToShortDateString(); reporteDispositivo.FechaHasta = fHasta.ToShortDateString(); reporteDispositivo.Consumo = consumo; reporteDispositivoColeccion.InsertOne(reporteDispositivo); } break; case "transformador": consumo = Reporte.consumoTransformadorPorPeriodo(Convert.ToInt32(idObjeto), fDesde, fHasta); dBContext = new MongoDBContext(); reporteTransformadorColeccion = dBContext.database.GetCollection <ReporteTransformador>("transformadorPorPeriodo"); int busquedaHistoricoTrans = 0; busquedaHistoricoTrans = (from t in reporteTransformadorColeccion.AsQueryable <ReporteTransformador>() where t.Codigo == Convert.ToInt32(idObjeto) && t.FechaDesde == fDesde.ToShortDateString() && (t.FechaHasta == fHasta.ToShortDateString() || t.FechaHasta == DateTime.Now.ToShortDateString()) && t.Consumo == consumo select t).Count(); if (busquedaHistoricoTrans == 0) { reporteCreado.Codigo = Convert.ToInt32(idObjeto); reporteCreado.FechaDesde = fDesde.ToShortDateString(); reporteCreado.FechaHasta = fHasta.ToShortDateString(); reporteCreado.Consumo = consumo; reporteTransformadorColeccion.InsertOne(reporteCreado); //inserta documentos a la coleccion especificada } break; default: return(Json(new { success = false, error = "No se reconoce el tipo de reporte" })); } return(Json(new { success = true, resultado = consumo, tipoReporte = tipoReporte })); }
public static void Update(FundInvestment investement) { MongoDBContext _client = new MongoDBContext(_settings.MongoDBConnectionString); _client.SaveDocument <FundInvestment>(investement, FUND_INVESTMENTS_COLLECTION); }
public ProductService() { _dbContext = new MongoDBContext(); _productCollection = _dbContext.Database.GetCollection <Product> (ConfigurationManager.AppSettings["ProductCollectionName"]); }
public BorrowerService(IOptions <Settings> settings) { _context = new MongoDBContext(settings); }
public UserService(IConfiguration config) { _context = new MongoDBContext(config); }
public StockQuotesInfoRepository(MongoDBContext monoDBContext) : base(monoDBContext) { CollectionName = "StockQuotes"; }
public ProfileRepository(MongoDBContext mongoDbContext) { collection = mongoDbContext.Database.GetCollection <DomainModels.Profile>("profiles"); }
public HomeRepository(MongoDBContext context) : base(context) { SetCollection("home"); }
public HomeController() { dbcontext = new MongoDBContext(); userCollection = dbcontext.database.GetCollection <User>("user"); }
private static void Proccess(List <AttLog> attlogs, string location, bool mode, string connectString, string linkChamCong, bool modeEmail) { #region Connection MongoDBContext.ConnectionString = connectString; MongoDBContext.DatabaseName = "tribat"; MongoDBContext.IsSSL = true; MongoDBContext dbContext = new MongoDBContext(); #endregion #region Config var dateNewPolicy = new DateTime(2018, 10, 01); double workingScheduleHour = 8; var lunch = TimeSpan.FromHours(1); #endregion var groups = (from p in attlogs group p by new { p.EnrollNumber, p.Date.Date } into d select new { groupDate = d.Key.Date.ToString("yyyy-MM-dd"), groupCode = d.Key.EnrollNumber, count = d.Count(), times = d.ToList(), }).ToList(); foreach (var group in groups) { Console.WriteLine("Date: " + group.groupDate + ", fingerCode: " + group.groupCode + ", location: " + location); try { var dateData = DateTime.ParseExact(group.groupDate, "yyyy-MM-dd", CultureInfo.InvariantCulture); var workTime = new TimeSpan(0); double workDay = 1; var late = new TimeSpan(0); var early = new TimeSpan(0); // 0: cần xác nhận công; 1: đủ ngày công ; 2: đã gửi xác nhận công, 3: đồng ý; 4: từ chối var status = 1; var statusLate = 1; var statusEarly = 1; var linkFinger = string.Empty; var enrollNumber = group.groupCode; var records = group.times.OrderBy(m => m.Date).ToList(); var dateFinger = records.First().DateOnlyRecord; var inLogTime = records.First().TimeOnlyRecord; var outLogTime = records.Last().TimeOnlyRecord; #region Save to db: In/Out log TimeSpan?dbinLogTime = inLogTime; TimeSpan?dboutLogTime = outLogTime; #endregion #region Define working hour schedule & email send notice var employeeId = string.Empty; var email = string.Empty; var fullName = string.Empty; var title = string.Empty; var startWorkingScheduleTime = TimeSpan.FromHours(8); var endWorkingScheduleTime = TimeSpan.FromHours(17); var filterEmp = Builders <Employee> .Filter.ElemMatch(z => z.Workplaces, a => a.Fingerprint == enrollNumber); var employee = dbContext.Employees.Find(filterEmp).FirstOrDefault(); if (employee != null) { employeeId = employee.Id; var workplaces = employee.Workplaces; if (workplaces != null && workplaces.Count > 0) { foreach (var workplace in employee.Workplaces) { if (!string.IsNullOrEmpty(workplace.Fingerprint) && workplace.Fingerprint == enrollNumber) { startWorkingScheduleTime = TimeSpan.Parse(workplace.WorkingScheduleTime.Split('-')[0].Trim()); endWorkingScheduleTime = TimeSpan.Parse(workplace.WorkingScheduleTime.Split('-')[1].Trim()); } } } email = employee.Email; fullName = employee.FullName; title = employee.Title; linkFinger = linkChamCong + employee.Id; } #endregion #region Procees Times // No Data if (!dbinLogTime.HasValue && !dboutLogTime.HasValue) { workTime = new TimeSpan(0); workDay = 0; status = 0; } else { if (group.times != null && group.times.Count > 1) { if (dateFinger < dateNewPolicy) { status = 1; statusEarly = 1; statusLate = 1; workDay = 1; workTime = TimeSpan.FromHours(8); } else { // Rule: If the start time is before the starting hours, set it to the starting hour. // New Rule: // ** Nếu không được xác nhận công: // - Trễ 15 phút không tính buổi nào không tính buổi đó. (1 buổi tương đương 0.5 ngày) // - Trễ dưới 15 phút lưu để trừ thưởng,... if (inLogTime < startWorkingScheduleTime) { inLogTime = startWorkingScheduleTime; } if (outLogTime > endWorkingScheduleTime) { outLogTime = endWorkingScheduleTime; } workTime = (outLogTime - inLogTime) - lunch; //workDay = workTime.TotalHours / workingScheduleHour; if (inLogTime > startWorkingScheduleTime) { late = inLogTime - startWorkingScheduleTime; statusLate = 0; status = 0; //workDay = workDay - 0.5; } if (outLogTime < endWorkingScheduleTime) { early = endWorkingScheduleTime - outLogTime; statusEarly = 0; status = 0; //workDay = workDay - 0.5; } } } else { // Check miss in/out var workingArr = new int[] { startWorkingScheduleTime.Hours, endWorkingScheduleTime.Hours }; var incheck = workingArr.ClosestTo(dbinLogTime.Value.Hours); var outcheck = workingArr.ClosestTo(dboutLogTime.Value.Hours); if (incheck == outcheck) { if (incheck == endWorkingScheduleTime.Hours) { // missing in dbinLogTime = null; late = new TimeSpan(0); early = endWorkingScheduleTime - outLogTime; workTime = TimeSpan.FromHours(4) - early; statusLate = 0; } else { // missing out dboutLogTime = null; early = new TimeSpan(0); late = inLogTime - startWorkingScheduleTime; workTime = TimeSpan.FromHours(4) - late; statusEarly = 0; } status = 0; workDay = 0.5; //workDay = workTime.TotalHours / workingScheduleHour; } if (dateFinger < dateNewPolicy) { status = 1; statusEarly = 1; statusLate = 1; workDay = 0.5; workTime = TimeSpan.FromHours(4); } } } var employeeWorkTimeLog = new EmployeeWorkTimeLog { EmployeeId = employeeId, EmployeeName = fullName, EmployeeTitle = title, EnrollNumber = enrollNumber, VerifyMode = records[0].VerifyMode, InOutMode = records[0].InOutMode, Workcode = records[0].Workcode, WorkplaceCode = location, Date = dateFinger, In = dbinLogTime, Out = dboutLogTime, Start = startWorkingScheduleTime, End = endWorkingScheduleTime, WorkTime = workTime, WorkDay = workDay, Late = late, Early = early, Status = status, StatusLate = statusLate, StatusEarly = statusEarly, Logs = records }; #region DB // mode = true: Get all data // mode = false: get by date if (mode) { dbContext.EmployeeWorkTimeLogs.InsertOne(employeeWorkTimeLog); Console.WriteLine("Insert db: EnrollNumber: " + employeeWorkTimeLog.EnrollNumber + ", date" + employeeWorkTimeLog.Date + ", status : " + employeeWorkTimeLog.Status); UpdateSummary(dbContext, dateData, employeeWorkTimeLog); } else { var employeeWorkTimeLogDb = dbContext.EmployeeWorkTimeLogs.Find(m => m.EnrollNumber.Equals(employeeWorkTimeLog.EnrollNumber) && m.Date.Equals(employeeWorkTimeLog.Date)).FirstOrDefault(); if (employeeWorkTimeLogDb == null) { dbContext.EmployeeWorkTimeLogs.InsertOne(employeeWorkTimeLog); Console.WriteLine("Insert db: EnrollNumber: " + employeeWorkTimeLog.EnrollNumber + ", date" + employeeWorkTimeLog.Date + ", status : " + employeeWorkTimeLog.Status); UpdateSummary(dbContext, dateData, employeeWorkTimeLog); } else { if (employeeWorkTimeLogDb.Status == 0) { var currentWorkTime = employeeWorkTimeLogDb.WorkTime.TotalMilliseconds; var currentLate = employeeWorkTimeLogDb.Late.TotalMilliseconds; var currentEarly = employeeWorkTimeLogDb.Early.TotalMilliseconds; var currentWorkDay = employeeWorkTimeLogDb.WorkDay; var builderUpdate = Builders <EmployeeWorkTimeLog> .Filter; var filterUpdate = builderUpdate.Eq(m => m.Id, employeeWorkTimeLogDb.Id); var update = Builders <EmployeeWorkTimeLog> .Update .Set(m => m.In, employeeWorkTimeLog.In) .Set(m => m.Out, employeeWorkTimeLog.Out) .Set(m => m.WorkTime, employeeWorkTimeLog.WorkTime) .Set(m => m.WorkDay, employeeWorkTimeLog.WorkDay) .Set(m => m.Late, employeeWorkTimeLog.Late) .Set(m => m.Early, employeeWorkTimeLog.Early) .Set(m => m.Status, employeeWorkTimeLog.Status) .Set(m => m.Logs, employeeWorkTimeLog.Logs) .Set(m => m.UpdatedOn, DateTime.Now); dbContext.EmployeeWorkTimeLogs.UpdateOne(filterUpdate, update); UpdateSummaryChangeData(dbContext, dateData, employeeWorkTimeLog, currentWorkTime, currentLate, currentEarly, currentWorkDay); } } } #endregion #endregion #region Send Mail if (modeEmail) { if (status == 0 && dateData == DateTime.Now.Date.AddDays(-1) && !string.IsNullOrEmpty(email)) { email = "*****@*****.**"; Console.WriteLine("Sending mail..."); var tos = new List <EmailAddress> { new EmailAddress { Name = fullName, Address = email } }; var webRoot = Environment.CurrentDirectory; var pathToFile = Environment.CurrentDirectory + "/Templates/TimeKeeperNotice.html"; var subject = "Xác nhận thời gian làm việc."; var bodyBuilder = new BodyBuilder(); using (StreamReader SourceReader = File.OpenText(pathToFile)) { bodyBuilder.HtmlBody = SourceReader.ReadToEnd(); } #region parameters //{0} : Subject //{1} : FullName //{2} : EnrollNumber //{3} : Workplace //{4} : WorkingScheduleTime //{5} : Date //{6} : In //{7} : Out //{8} : Late //{9} : Early //{10}: workTime //{11}: workDay //{12}: logs //{13}: callbackLink //{14}: Website //{15}: link forgot password => use login //{16}: ConfirmBeforeDate #endregion var url = Constants.System.domain; var forgot = url + Constants.System.login; string messageBody = string.Format(bodyBuilder.HtmlBody, subject, fullName, employeeWorkTimeLog.EnrollNumber, employeeWorkTimeLog.WorkplaceCode, employeeWorkTimeLog.Start + "-" + employeeWorkTimeLog.End, employeeWorkTimeLog.Date.ToString("dd/MM/yyyy"), employeeWorkTimeLog.In, employeeWorkTimeLog.Out, employeeWorkTimeLog.Late == TimeSpan.FromHours(0) ? string.Empty : employeeWorkTimeLog.Late.ToString(), employeeWorkTimeLog.Early == TimeSpan.FromHours(0) ? string.Empty : employeeWorkTimeLog.Early.ToString(), employeeWorkTimeLog.WorkTime, Math.Round(employeeWorkTimeLog.WorkDay, 2), employeeWorkTimeLog.Logs, linkChamCong, url, forgot, DateTime.Now.AddDays(1).ToShortDateString() ); var emailMessage = new EmailMessage() { ToAddresses = tos, Subject = subject, BodyContent = messageBody }; new AuthMessageSender().SendEmail(emailMessage); } } #endregion } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
private static void UpdateFinal(MongoDBContext dbContext) { // Update missing Date, Leave date, apply allow late|early,... // Apply current month var endDate = Utility.WorkingMonthToDate(DateTime.Now.Month + "-" + DateTime.Now.Year); var startDate = endDate.AddMonths(-1).AddDays(1); int yearCurrent = endDate.Year; int monthCurrent = endDate.Month; // For each employee have finger code // For startDate = > to Date. If missing and not sunday add missing times, if leave add reason leave- status. // if In date late or early, check allow count. update order a->n if still allow count. var filterEmployees = Builders <Employee> .Filter.ElemMatch(z => z.Workplaces, a => !string.IsNullOrEmpty(a.Fingerprint)); var employees = dbContext.Employees.Find(filterEmployees).ToList(); foreach (var employee in employees) { var monthTimeInformation = dbContext.EmployeeWorkTimeMonthLogs.Find(m => m.EmployeeId.Equals(employee.Id) && m.Year.Equals(yearCurrent) && m.Month.Equals(monthCurrent)).FirstOrDefault(); if (monthTimeInformation != null) { var missingMinuteAllow = monthTimeInformation.MissingMinuteAllow; var missingMinuteAllowUsed = monthTimeInformation.MissingMinuteAllowUsed; var missingMinuteAllowCanUse = missingMinuteAllow - missingMinuteAllowUsed; int missingMinuteAllowUsedCount = 0; //var lateCountAllow = monthTimeInformation.LateCountAllow; //double lateCountAllowUsed = monthTimeInformation.LateCountAllowUsed; //int lateMinuteAllow = monthTimeInformation.LateMinuteAllow; //var earlyCountAllow = monthTimeInformation.LateCountAllow; //double earlyCountAllowUsed = monthTimeInformation.EarlyCountAllowUsed; //int earlyMinuteAllow = monthTimeInformation.EarlyMinuteAllow; int noFingerDate = monthTimeInformation.NoFingerDate; double lateApprove = monthTimeInformation.LateApprove; double earlyApprove = monthTimeInformation.EarlyApprove; // get times data in current month (EmployeeWorkTimeLog) var builder = Builders <EmployeeWorkTimeLog> .Filter; var filter = builder.Eq(m => m.EmployeeId, employee.Id); //filter = filter & builder.Gte(m => m.Date, startDate) & builder.Lte(m => m.Date, endDate); filter = filter & builder.Gt(m => m.Date, startDate.AddDays(-1)) & builder.Lt(m => m.Date, endDate.AddDays(1)); var timekeepings = dbContext.EmployeeWorkTimeLogs.Find(filter).ToList(); // get leaves data. remember remove sunday. var builderLeaves = Builders <Leave> .Filter; var filterLeaves = builderLeaves.Eq(m => m.EmployeeId, employee.Id); filterLeaves = filterLeaves & builderLeaves.Gt(m => m.From, startDate) & builderLeaves.Lte(m => m.To, endDate); var leaves = dbContext.Leaves.Find(filterLeaves).ToList(); decimal workday = 0; var late = new TimeSpan(0); var early = new TimeSpan(0); decimal sundayCount = 0; decimal ngayNghiHuongLuong = 0; decimal ngayNghiLeTetHuongLuong = 0; decimal congCNGio = 0; decimal congTangCaNgayThuongGio = 0; decimal congLeTet = 0; decimal holidayCount = 0; decimal leaveCount = 0; decimal leaveNotApproveCount = 0; decimal leaveAprovedCount = 0; for (DateTime date = startDate; date <= DateTime.Now; date = date.AddDays(1)) { var timekeeping = timekeepings.FirstOrDefault(item => item.Date == date); // if exist check allow late|early if (timekeeping != null) { // Cần xác nhận công (status = 0); int status = timekeeping.Status; int statusLate = timekeeping.StatusLate; int statusEarly = timekeeping.StatusEarly; if (status == 0) { if (statusLate == 0 && timekeeping.In.HasValue) { var lateMinute = timekeeping.Late.TotalMinutes; if (lateMinute > 15) { // Trừ 0.5 ngay var filterUpdate = Builders <EmployeeWorkTimeLog> .Filter.Eq(m => m.Id, timekeeping.Id); var update = Builders <EmployeeWorkTimeLog> .Update .Inc(m => m.WorkDay, -0.5); dbContext.EmployeeWorkTimeLogs.UpdateOne(filterUpdate, update); workday += (decimal)0.5; late += timekeeping.Late; } //if (lateMinute <= missingMinuteAllow && lateMinute <= missingMinuteAllowCanUse) //{ // lateApprove += timekeeping.Late.TotalMilliseconds; // statusLate = 3; // if (statusEarly == 1 || statusEarly == 3) // { // status = 5; // } // var filterUpdate = Builders<EmployeeWorkTimeLog>.Filter.Eq(m => m.Id, timekeeping.Id); // var update = Builders<EmployeeWorkTimeLog>.Update // .Inc(m => m.WorkDay, 0.5) // .Set(m => m.StatusLate, statusLate) // .Set(m => m.Status, status) // .Set(m => m.UpdatedBy, Constants.System.account) // .Set(m => m.UpdatedOn, DateTime.Now); // dbContext.EmployeeWorkTimeLogs.UpdateOne(filterUpdate, update); // missingMinuteAllowCanUse -= lateMinute; // workday += (decimal)0.5; // missingMinuteAllowUsedCount++; //} } if (statusEarly == 0 && timekeeping.Out.HasValue) { var earlyMinute = timekeeping.Early.TotalMinutes; if (earlyMinute > 15) { // Trừ 0.5 ngay var filterUpdate = Builders <EmployeeWorkTimeLog> .Filter.Eq(m => m.Id, timekeeping.Id); var update = Builders <EmployeeWorkTimeLog> .Update .Inc(m => m.WorkDay, -0.5); dbContext.EmployeeWorkTimeLogs.UpdateOne(filterUpdate, update); workday += (decimal)0.5; early += timekeeping.Late; } //if (earlyMinute <= missingMinuteAllow && earlyMinute <= missingMinuteAllowCanUse) //{ // // xac nhan // earlyApprove += timekeeping.Early.TotalMilliseconds; // statusEarly = 3; // if (statusLate == 1 || statusLate == 3) // { // status = 5; // } // var filterUpdate = Builders<EmployeeWorkTimeLog>.Filter.Eq(m => m.Id, timekeeping.Id); // var update = Builders<EmployeeWorkTimeLog>.Update // .Inc(m => m.WorkDay, 0.5) // .Set(m => m.StatusEarly, statusEarly) // .Set(m => m.Status, status) // .Set(m => m.UpdatedBy, Constants.System.account) // .Set(m => m.UpdatedOn, DateTime.Now); // dbContext.EmployeeWorkTimeLogs.UpdateOne(filterUpdate, update); // missingMinuteAllowCanUse -= earlyMinute; // workday += (decimal)0.5; // missingMinuteAllowUsedCount++; //} } #region Comment rule late & early //if (statusLate == 0 && timekeeping.In.HasValue && timekeeping.Late.TotalMinutes <= lateMinuteAllow) //{ // if (lateCountAllowUsed < lateCountAllow) // { // // xac nhan // lateApprove += timekeeping.Late.TotalMilliseconds; // statusLate = 3; // if (statusEarly == 1 || statusEarly == 3) // { // status = 3; // } // var filterUpdate = Builders<EmployeeWorkTimeLog>.Filter.Eq(m => m.Id, timekeeping.Id); // var update = Builders<EmployeeWorkTimeLog>.Update // .Set(m => m.StatusLate, statusLate) // .Set(m => m.Status, status) // .Set(m => m.UpdatedBy, Constants.System.account) // .Set(m => m.UpdatedOn, DateTime.Now); // dbContext.EmployeeWorkTimeLogs.UpdateOne(filterUpdate, update); // lateCountAllowUsed++; // } //} //if (statusEarly == 0 && timekeeping.Out.HasValue && timekeeping.Early.TotalMinutes <= earlyMinuteAllow) //{ // if (earlyCountAllowUsed < earlyCountAllow) // { // // xac nhan // earlyApprove += timekeeping.Early.TotalMilliseconds; // statusEarly = 3; // if (statusLate == 1 || statusLate == 3) // { // status = 3; // } // var filterUpdate = Builders<EmployeeWorkTimeLog>.Filter.Eq(m => m.Id, timekeeping.Id); // var update = Builders<EmployeeWorkTimeLog>.Update // .Set(m => m.StatusEarly, statusEarly) // .Set(m => m.Status, status) // .Set(m => m.UpdatedBy, Constants.System.account) // .Set(m => m.UpdatedOn, DateTime.Now); // dbContext.EmployeeWorkTimeLogs.UpdateOne(filterUpdate, update); // earlyCountAllowUsed++; // } //} #endregion } } else { // Add missing data(leave,sunday, le, tet...) if (date.DayOfWeek == DayOfWeek.Sunday) { var employeeWorkTimeLog = new EmployeeWorkTimeLog { EmployeeId = employee.Id, Year = yearCurrent, Month = monthCurrent, Date = date, Workcode = "Chủ nhật" }; dbContext.EmployeeWorkTimeLogs.InsertOne(employeeWorkTimeLog); // Add Sunday sundayCount++; } else { var existLeave = leaves.FirstOrDefault(item => item.Enable.Equals(true) && date >= item.From.Date && date <= item.To.Date); if (existLeave != null) { // add leave var workCode = existLeave.TypeName; var status = existLeave.Status; //var leaveTypeId = existLeave.TypeId; switch (status) { case 0: workCode += " (chờ duyệt)"; break; case 1: workCode += " (đã duyệt)"; break; case 2: workCode += " (không duyệt)"; break; case 3: workCode += " (tạm hoãn và chờ duyệt)"; break; } var employeeWorkTimeLog = new EmployeeWorkTimeLog { EmployeeId = employee.Id, Year = yearCurrent, Month = monthCurrent, Date = date, WorkTime = new TimeSpan(0, 0, 0), InOutMode = "1", Workcode = workCode }; dbContext.EmployeeWorkTimeLogs.InsertOne(employeeWorkTimeLog); // phan loai nghi if (existLeave.TypeId == "5bb45d407fe7602e04fb5981") { ngayNghiHuongLuong++; } leaveCount++; } else { // add missing date // If now if (date != DateTime.Now.Date) { var employeeWorkTimeLog = new EmployeeWorkTimeLog { EmployeeId = employee.Id, Year = yearCurrent, Month = monthCurrent, Date = date, WorkTime = new TimeSpan(0, 0, 0), StatusLate = 0, StatusEarly = 0, Status = 0, Workcode = "0" }; dbContext.EmployeeWorkTimeLogs.InsertOne(employeeWorkTimeLog); noFingerDate++; } else { var employeeWorkTimeLog = new EmployeeWorkTimeLog { EmployeeId = employee.Id, Year = yearCurrent, Month = monthCurrent, Date = date, WorkTime = new TimeSpan(0, 0, 0), StatusLate = 0, StatusEarly = 0, Status = 0, Workcode = "Chờ chấm công" }; dbContext.EmployeeWorkTimeLogs.InsertOne(employeeWorkTimeLog); } } } } } #region update Summarry var builderUpdateSum = Builders <EmployeeWorkTimeMonthLog> .Filter; //m => m.EnrollNumber.Equals(employeeWorkTimeLog.EnrollNumber) && m.Year.Equals(year) && m.Month.Equals(month) var filterUpdateSum = builderUpdateSum.Eq(m => m.EmployeeId, employee.Id); filterUpdateSum = filterUpdateSum & builderUpdateSum.Eq(m => m.Year, endDate.Year); filterUpdateSum = filterUpdateSum & builderUpdateSum.Eq(m => m.Month, endDate.Month); var updateSum = Builders <EmployeeWorkTimeMonthLog> .Update //.Set(m => m.LateCountAllowUsed, lateCountAllowUsed) //.Set(m => m.EarlyCountAllowUsed, earlyCountAllowUsed) .Set(m => m.MissingMinuteAllowUsed, missingMinuteAllow - missingMinuteAllowCanUse) .Inc(m => m.MissingMinuteAllowUsedCount, missingMinuteAllowUsedCount) .Inc(m => m.Workday, -(double)workday) .Inc(m => m.Late, -late.TotalMilliseconds) .Inc(m => m.Early, -early.TotalMilliseconds) .Set(m => m.LateApprove, lateApprove) .Set(m => m.EarlyApprove, earlyApprove) .Set(m => m.Sunday, (double)sundayCount) .Set(m => m.Holiday, (double)holidayCount) .Set(m => m.NgayNghiHuongLuong, (double)ngayNghiHuongLuong) .Set(m => m.LeaveDate, (double)leaveCount) .Set(m => m.LeaveDateApproved, (double)leaveAprovedCount) .Set(m => m.LeaveDateNotApprove, (double)leaveNotApproveCount) .Set(m => m.NoFingerDate, noFingerDate) .Set(m => m.LastUpdated, DateTime.Now); dbContext.EmployeeWorkTimeMonthLogs.UpdateOne(filterUpdateSum, updateSum); #endregion } } }
public FilesController() { mongoDB = new MongoDBContext(); }
public TurmaCaching(MongoDBContext mongoDBContext) { this.mongoDBContext = mongoDBContext; }
public BookRepository(IDBContext <Book> dbContextBook) { _dbContext = (MongoDBContext <Book>)dbContextBook; }
public MovieRepository(IConfiguration config) { _config = config; _context = new MongoDBContext(config); }
public PatientsController() { _context = new MongoDBContext(); _spec = new PopulateSpecilizations(); _table = "Patients"; }
public CitasController() { dbcontext = new MongoDBContext(); CitasCollection = dbcontext.database.GetCollection <CitasModel>("Citas"); }
public InsurancePolicyService(IOptions <Settings> settings) { _context = new MongoDBContext(settings); }
public MessageService(MongoDBContext db) : base(db, ModelCollectionName.Message) { }
public RoutingRepository(IAuthorizationDbContext ctx, INetworkingDbContext tctx, MongoDBContext mctx) { this.m_ctx = ctx; this.m_networkContext = tctx; this.m_sensors = mctx.Sensors; }
public MongoDBController() { dbContext = new MongoDBContext(); pc = dbContext.database.GetCollection <MongoDBModel>("Logs"); }
public static void SaveDailyActivity(List <FundInvestment> investements) { MongoDBContext _client = new MongoDBContext(_settings.MongoDBConnectionString); _client.InsertDocuments <FundInvestment>(investements, FUND_INVESTMENTS_COLLECTION); }
//static void Main(string[] args) public static async Task Main(string[] args) { WriteLine("Hello World!"); if (!await MongoDBContext.UpdateProductsAsync()) { Environment.Exit(1); } Console.WriteLine("Finished updating the product collection"); Console.ReadKey(); //MongoCRUD db = new MongoCRUD("AddressBook"); //PersonModel person = new PersonModel() //{ // FristName = "Joao", // LastName = "Da Silva", // PrimaryAddress = new AddressModel // { // StreetAddress = "101 oak Street", // City = "Contagem", // State = "MG", // ZipCode = "32323232" // } //}; // create //db.InsertRecord("User", new PersonModel() { FristName = "Maravilha", LastName = "Lopes" }); //db.InsertRecord("User", person); // list //var recs = db.LoadRecords<PersonModel>("User"); //foreach (var rec in recs) //{ // WriteLine($"{rec.Id} : {rec.FristName} {rec.LastName}"); // if (rec.PrimaryAddress != null) // { // WriteLine(rec.PrimaryAddress.City); // } //} //var recs = db.LoadRecords<NameModel>("User"); //foreach (var rec in recs) //{ // WriteLine($"{rec.FristName} {rec.LastName}"); // WriteLine(); //} // Get by Id //var person = db.LoadRecordById<PersonModel>("User", Guid.Parse("0af03115-b9be-480c-822c-418b3019eed3")); // update //person.DateOfBirth = new DateTime(1979, 10, 31, 0, 0, 0, DateTimeKind.Utc); //db.UpdateInsertRecord("User", person.Id, person); // delete //db.DeleteRecord<PersonModel>("User", person.Id); ReadLine(); }
public PatientService(IConfiguration config) { _context = new MongoDBContext(config); }
public UserController() { dBContext = new MongoDBContext(); userCollection = dBContext.database.GetCollection <UserModel>("users"); }
static void Main(string[] args) { #region Connection, Setting & Filter var debug = ConfigurationSettings.AppSettings.Get("debugString").ToString(); var connection = ConfigurationSettings.AppSettings.Get("connection").ToString(); var database = ConfigurationSettings.AppSettings.Get("database").ToString(); MongoDBContext.ConnectionString = connection; MongoDBContext.DatabaseName = database; MongoDBContext.IsSSL = true; MongoDBContext dbContext = new MongoDBContext(); var url = Constants.System.domain; #endregion // ngày 01 hàng tháng run. var now = DateTime.Now.Date; var month = now.Month; var year = now.Year; var endDateMonth = now.AddDays(-1); #region Filter var builder = Builders <Employee> .Filter; var filter = !builder.Eq(i => i.UserName, Constants.System.account) & builder.Eq(m => m.Enable, true) & builder.Eq(m => m.IsOnline, true); if (!string.IsNullOrEmpty(debug)) { filter &= builder.Eq(m => m.Id, debug); } #endregion var employees = dbContext.Employees.Find(filter).ToList(); var leaveType = dbContext.LeaveTypes.Find(m => m.Alias.Equals("phep-nam")).FirstOrDefault(); var leaveTypeId = leaveType.Id; foreach (var employee in employees) { // default, normal employee double numLeave = 1; var description = "Cộng từng tháng: " + numLeave + " ngày;"; var employeeId = employee.Id; var thamnienlamviec = employee.Joinday; // Included probation var bacphep = employee.LeaveLevelYear; var hesophep = Convert.ToInt32(bacphep - 12); if (hesophep > 0) { // Cộng mức phép năm đầu quí. // Theo ngay vào làm || dau nam. var dateApplyHeSo = thamnienlamviec; // new DateTime(year, 01, 01) // Theo ngay vao lam. // 2 : chia cho 6 thang | 4 : chia cho 3 thang for (int i = 0; i < hesophep; i++) { var xetmucphep = dateApplyHeSo.AddMonths(12 / hesophep * i); var thangxetmucphep = dateApplyHeSo.AddMonths((12 / hesophep) * i).Month; if (thangxetmucphep == month) { numLeave += 1; description = "Cộng mức phép: 1 ngày;"; } } } // Rule tham nien: 5 năm + 1 ngày phép & áp dụng vào đầu tháng var ngaythamnien = (endDateMonth - thamnienlamviec).TotalDays; double thangthamnien = Math.Round(ngaythamnien / 30, 0); double namthamnien = Math.Round(thangthamnien / 12, 0); var ngayphepthamnien = 0; if (namthamnien >= 5) { for (int i = 5; i <= namthamnien; i += 5) { ngayphepthamnien++; } } if (ngayphepthamnien > 0) { if (thamnienlamviec.Month == month) { numLeave += ngayphepthamnien; description = "Cộng thâm niên: " + ngayphepthamnien + " ngày;"; } } // Probation // Use UseFlag in [LeaveEmployees] // probation default 2 months var useFlag = true; var probationEndDate = thamnienlamviec.AddMonths(2); if (now < probationEndDate) { useFlag = false; } // Check exist leaveEmployee var leaveE = dbContext.LeaveEmployees.Find(m => m.EmployeeId.Equals(employeeId)).FirstOrDefault(); if (leaveE == null) { var leaveEmployeeNew = new LeaveEmployee() { LeaveTypeId = leaveTypeId, EmployeeId = employeeId, LeaveTypeName = leaveType.Name, EmployeeName = employee.FullName, Number = numLeave, Department = employee.PhongBanName, Part = employee.BoPhanName, Title = employee.ChucVuName, LeaveLevel = Convert.ToDouble(employee.LeaveLevelYear), NumberUsed = 0, UseFlag = useFlag, Year = DateTime.Now.Year }; dbContext.LeaveEmployees.InsertOne(leaveEmployeeNew); dbContext.LeaveEmployeeHistories.InsertOne(new LeaveEmployeeHistory { EmployeeId = employeeId, LeaveTypeId = leaveTypeId, Current = 0, Change = numLeave, Month = month, Year = year, Description = description }); } else { // No update if updated var updated = dbContext.LeaveEmployeeHistories.CountDocuments(m => m.EmployeeId.Equals(employeeId) && m.Month.Equals(month) && m.Year.Equals(year)) > 0 ? false : true; if (updated) { double currentLeaveNum = 0; var currentLeave = dbContext.LeaveEmployees.Find(m => m.EmployeeId.Equals(employeeId) && m.LeaveTypeId.Equals(leaveTypeId)).FirstOrDefault(); if (currentLeave != null) { currentLeaveNum = currentLeave.Number; } // Missing here, if no LeaveEmployee ?? // Update LeaveEmployees var filterLeaveEmployee = Builders <LeaveEmployee> .Filter.Eq(m => m.EmployeeId, employeeId); var updateLeaveEmployee = Builders <LeaveEmployee> .Update .Set(m => m.UseFlag, useFlag) .Inc(m => m.Number, numLeave) .Set(m => m.UpdatedOn, now); dbContext.LeaveEmployees.UpdateOne(filterLeaveEmployee, updateLeaveEmployee); //Add LeaveEmployeeHistories dbContext.LeaveEmployeeHistories.InsertOne(new LeaveEmployeeHistory { EmployeeId = employeeId, LeaveTypeId = leaveTypeId, Current = currentLeaveNum, Change = numLeave, Month = month, Year = year, Description = description }); } } } }
static void UpdateTimeKeeper() { //var connectString = "mongodb://192.168.2.223:27017"; var connectString = "mongodb://localhost:27017"; #region Connection MongoDBContext.ConnectionString = connectString; MongoDBContext.DatabaseName = "tribat"; MongoDBContext.IsSSL = true; MongoDBContext dbContext = new MongoDBContext(); #endregion #region Setting // mode = true: Get all data // mode = false: get by date var mode = true; var day = -30; var modeEmail = false; var linkChamCong = Constants.System.domain + "/" + Constants.LinkTimeKeeper.Main + "/" + Constants.LinkTimeKeeper.Index; var dateCrawled = DateTime.Now.AddDays(day); var builder = Builders <AttLog> .Filter; var filter = builder.Gt(m => m.Date, dateCrawled.AddDays(-1)); #endregion //#region UAT //var uat = dbContext.Settings.Find(m => m.Key.Equals("UAT")).FirstOrDefault(); //if (uat != null && uat.Value == "true") //{ // dbContext.EmployeeWorkTimeLogs.DeleteMany(m => true); // dbContext.EmployeeWorkTimeMonthLogs.DeleteMany(m => true); // filter = filter & builder.Eq(m => m.EnrollNumber, "514"); //} //#endregion dbContext.EmployeeWorkTimeLogs.DeleteMany(m => true); dbContext.EmployeeWorkTimeMonthLogs.DeleteMany(m => true); if (mode) { dbContext.EmployeeWorkTimeLogs.DeleteMany(m => true); dbContext.EmployeeWorkTimeMonthLogs.DeleteMany(m => true); } var attlogVps = mode ? dbContext.X628CVPAttLogs.Find(m => true).ToList() : dbContext.X628CVPAttLogs.Find(filter).ToList(); if (attlogVps != null && attlogVps.Count > 0) { Proccess(attlogVps, "VP", mode, connectString, linkChamCong, modeEmail); } #region UAT //if (uat != null && uat.Value == "true") //{ // builder = Builders<AttLog>.Filter; // filter = builder.Gt(m => m.Date, dateCrawled.AddDays(-1)); // filter = filter & builder.Eq(m => m.EnrollNumber, "259"); //} #endregion var attlogNMs = mode ? dbContext.X928CNMAttLogs.Find(m => true).ToList() : dbContext.X928CNMAttLogs.Find(filter).ToList(); if (attlogNMs != null && attlogNMs.Count > 0) { Proccess(attlogNMs, "NM", mode, connectString, linkChamCong, modeEmail); } UpdateFinal(dbContext); }