private static void UpdatePlan(Plan plan, bool isPlanned = false) { try { var flights = plan.Flights; if (isPlanned) { plan.PlannedBudget = flights.Sum(x => x.PlannedBudget); } else { plan.ActualBudget = flights.Sum(x => x.ActualBudget); } plan.LastUpdate = Constants.TotalMilliseconds; var planRepo = new PlanRepository(actionCode: (int)Constants.PlanAction.Code, code: plan.Code); planRepo.UpdatePlan(plan, new List <int>() { (int)Constants.PlanField.LastUpdate, isPlanned ? (int)Constants.PlanField.PlannedBudget : (int)Constants.PlanField.ActualBudget }); } catch (Exception ex) { Logger.Logger.WriteError(ex); } }
public static bool ApprovePlan(int code) { var user = UserSession.Current.User; if (user != null) { var repo = new PlanRepository(false, (int)Constants.PlanAction.Code, code); if (repo.List.Any()) { var plan = repo.List.FirstOrDefault(); if (plan.ExecutorCode == user.Code) { if (UpdateStatus(plan, repo, (int)Constants.WorkflowStatus.Approved) != null) { var task = new Task(() => InformationManager.PlanApprove(plan, user.FamilyCode)); task.Start(); var task2 = new Task(() => TemplateManager.UpdatePlan(plan)); task2.Start(); return(true); } } } } throw new Exception(); }
public void CanGetById() { var provider = new PlanStorageProviderMonitor(GenerateRefTree()); var repository = new PlanRepository(new PlanStorage(new PlanCache(new ExpirationStrategyMock()), provider)); Assert.AreEqual(NewGuid(2), repository.GetById <ActivityDO>(NewGuid(2)).Id); }
public Plans GetOne(string id) { return(PlanRepository.GetQuery(o => o.Id == id).Include(o => o.Attachments).Include(o => o.Replys).FirstOrDefault() ?? new Plans() { Attachments = new List <Attachment>() }); }
public PlanBusiness(IUnitOfWork _unitOfWork) { unitOfWork = _unitOfWork; planRepository = new PlanRepository(unitOfWork); moduleRepository = new ModuleRepository(unitOfWork); planModuleRepository = new PlanModuleRepository(unitOfWork); }
// POST: api/Plan public IHttpActionResult Post([FromBody] List <Plan> planList) { PlanRepository planRepository = new PlanRepository(Convert.ToInt32(Request.Headers.GetValues("CurrentUserID").First())); planRepository.SavePlans(planList); return(Json(new { count = planList.Count.ToString() })); }
public void SetUp() { var mapper = DtoMappings.GetMapperConfiguration().CreateMapper(); _shiftRepository = new ShiftRepository(_connection); _assignmentRepository = new AssignmentRepository(_connection, mapper); _planRepository = new PlanRepository(_connection, mapper); }
public void SetUp() { _mapper = DtoMappings.GetMapperConfiguration().CreateMapper(); _userRepository = new UserRepository(_connection); _assignmentRepository = new AssignmentRepository(_connection, _mapper); _planRepository = new PlanRepository(_connection, _mapper); _user = _userRepository.GetUser(1).Result; }
public IHttpActionResult Get() { PlanRepository planRepository = new PlanRepository(Convert.ToInt32(Request.Headers.GetValues("CurrentUserID").First())); List <Plan> planList = planRepository.GetPlans(); return(Json(new { plans = planList })); }
public OpResult UpdateStatus(string ids, short status) { var id = ids.Split(','); var list = PlanRepository.GetQuery(o => id.Contains(o.Id)).ToList(); list.Each(o => o.Status = status); PlanRepository.SaveChanges(); return(OpResult.Success()); }
public async Task <JsonResult> DelPlan(string planID) { using (PlanRepository planRepo = new PlanRepository()) { var res = await planRepo.DelPlanAsync(planID); return(Json(new { isOk = res })); } }
public async Task <JsonResult> GetPlanListAsync(int page, int rows, string title) { using (PlanRepository planRepo = new PlanRepository()) { var tuple = await planRepo.GetPlanListAsync(page, rows, title); return(Json(new { total = tuple.Item1, rows = tuple.Item2 })); } }
public AccountService() { repository = new AccountRepository(); userService = new UserService(); settingsRepository = new SettingsRepository(); planRepository = new PlanRepository(); virtualCardRepository = new VirtualCardRepository(); transactionsRepository = new TransactionHistoryRepository(); }
public PlanController(IConfiguration configuration, GHDbContext ghDbContext, IMapper mapper) { _PlanRepository = new PlanRepository(ghDbContext, mapper); _FileRepository = new PlanFileRepository(ghDbContext, mapper); if (configuration != null) { _FileBaseDir = Path.Combine(configuration["StaticFileDir"], "PlanFiles"); } }
public void TestInitialize() { _mockPlans = new Mock <DbSet <Plan> >(); var mockContext = new Mock <ApplicationDbContext>(); mockContext.SetupGet(c => c.Plans).Returns(_mockPlans.Object); _repository = new PlanRepository(mockContext.Object); }
public void SetUp() { _mapper = DtoMappings.GetMapperConfiguration().CreateMapper(); _planRepository = new PlanRepository(_connection, _mapper); _patrolRepository = new PatrolRepository(_connection); _userRepository = new UserRepository(_connection); _user = _userRepository.GetUser(1).Result; _patrol = _patrolRepository.GetPatrolsForUser(_user.Id).Result.First(x => x.Name == "Big Mountain Patrol"); _plan = _planRepository.GetPlansForPatrol(_patrol.Id).Result.First(x => x.Name == "Ski Alpine"); }
public List<PlanModel> GetPlans() { //unitOfWork.StartTransaction(); List<PlanModel> planModel = new List<PlanModel>(); List<Plan> plan = new List<Plan>(); PlanRepository planRepository = new PlanRepository(unitOfWork); plan = planRepository.GetAll().OrderByDescending(x=>x.PlanId).ToList(); //unitOfWork.Commit(); AutoMapper.Mapper.Map(plan,planModel); return planModel; }
public PlanModel GetPlanById(int planId) { //unitOfWork.StartTransaction(); PlanRepository planRepository = new PlanRepository(unitOfWork); PlanModel planModel = new PlanModel(); Plan plan = new Plan(); plan = planRepository.GetAll().Where(x => x.PlanId == planId).FirstOrDefault(); //unitOfWork.Commit(); AutoMapper.Mapper.Map(plan, planModel); return planModel; }
public UnitOfWork(TeoguideDbContext context) { _context = context; usuarioRepository = new UsuarioRepository(_context); planRepository = new PlanRepository(_context); actividadRepository = new ActividadRepository(_context); centroHistoricoRepository = new CentroHistoricoRepository(_context); multimediaRespository = new MultimediaRepository(_context); descripcionRepository = new DescripcionRepository(_context); comentarioRespository = new ComentarioRespository(_context); }
public object MyReplyIndexPageList(System.Collections.Specialized.NameValueCollection nvl, out int recordCount) { var type = nvl["Type"].ToType <short>(); var status = nvl["Status"].ToType <short>(); var begin = nvl["CreateDT_begin"].ToType <DateTime?>(); var end = nvl["CreateDT_end"].ToType <DateTime?>(); if (end.HasValue) { end = end.Value.AddDays(1); } var search = (nvl["SearchText"] ?? "").Trim(); var detail = nvl["detail"];//是否已批复 var queryUser = UserRepository.GetQuery(); var queryDict = DictRepository.GetQuery(); var where = DynamicallyLinqHelper.Empty <Plans>().And(o => o.Type == type, type == 0).And(o => o.Status == status, status == 0) .And(o => o.CreateDT >= begin, !begin.HasValue).And(o => o.CreateDT < end, !end.HasValue).And(o => o.Content.Contains(search), search.IsNullOrEmpty()) .And(o => o.LeaderUID.Contains(CurrentUser.UID)).And(o => !(o.Summary == null || o.Summary == "")); if (detail.IsNullOrEmpty()) { where = where.And(o => !o.Replys.Any()); } else { where = where.And(o => o.Replys.Any()); } var query = PlanRepository.GetQuery(where).Include(o => o.Attachments).Include(o => o.Replys); var q = from x in query select new { x.Id, x.AssignerUID, Assigner = queryUser.Where(o => o.UserId == x.AssignerUID).Select(o => o.FullName).FirstOrDefault(), Creater = queryUser.Where(o => o.UserId == x.CreateUID).Select(o => o.FullName).FirstOrDefault(), x.Content, AttachCount = x.Attachments.Count, x.CreateDT, x.CreateUID, x.StartDate, x.EndDate, ReplyCount = x.Replys.Count, x.Status, x.Type, x.Summary, StatuTitle = queryDict.Where(o => o.DicSN == x.Status).Select(o => o.Title).FirstOrDefault(), TypeTitle = queryDict.Where(o => o.DicSN == x.Type).Select(o => o.Title).FirstOrDefault(), }; recordCount = q.Count(); var list = q.ToPageList(); return(list); }
public static int GetCreatePlanUseTemplate(int code) { var user = UserSession.Current.User; if (user != null) { var repo = new TemplateRepository((int)Constants.TemplateAction.Plan, code, false); var template = repo.List.FirstOrDefault(); if (template == null) { throw new Exception(); } var planRepo = new PlanRepository(false, (int)Constants.PlanAction.Code, code); var plan = planRepo.List.FirstOrDefault(); if (plan != null) { var flights = plan.Flights; plan.CreateDate = Constants.TotalMilliseconds; plan.LastUpdate = Constants.TotalMilliseconds; plan.StartDate = Constants.TotalMilliseconds; plan.EndDate = Constants.TotalMilliseconds; plan.Name = plan.Name.Substring(0, plan.Name.Length - 12); plan.ActualBudget = 0; plan.PlannedBudget = flights.Sum(x => x.ActualBudget); plan.Status = (int)Constants.WorkflowStatus.InPlanned; code = planRepo.InsertData(plan); if (code == Constants.DEFAULT_CODE) { throw new Exception(); } template.SetPlanCode(code); repo.UpdateTemplate(template); var flightRepo = new FlightRepository(); foreach (var flight in flights) { flight.PlanCode = code; flight.PlannedBudget = flight.ActualBudget; flight.ActualBudget = 0; flight.OwnerCode = user.Code; flight.Status = (int)Constants.WorkflowStatus.InPlanned; flight.DateCreate = Constants.TotalMilliseconds; flightRepo.InsertData(flight); } return(code); } } throw new NotImplementedException(); }
public UnitOfWork(ApplicationDbContext context) { _context = context; Plans = new PlanRepository(context); Workouts = new WorkoutRepository(context); Exercises = new ExerciseRepository(context); Favourites = new FavouriteRepository(context); Genres = new GenreRepository(context); Ratings = new RatingRepository(context); TrainingTypes = new TrainingTypeRepository(context); Users = new UserRepository(context); Views = new ViewRepository(context); }
public async Task <JsonResult> GetPlanPointListAsync(int page, int rows, string planID, string itemID) { if (string.IsNullOrEmpty(planID)) { return(null); } using (PlanRepository planRepo = new PlanRepository()) { var tuple = await planRepo.GetPlanPointListAsync(page, rows, planID, itemID); return(Json(new { total = tuple.Item1, rows = tuple.Item2 })); } }
public async Task <JsonResult> SavePlan(Plan model) { using (PlanRepository planRepo = new PlanRepository()) { if (string.IsNullOrEmpty(model.PlanID)) { model.PlanID = CommonHelper.GetRandomString("PL"); } var res = await planRepo.AddOrUpdatePlanAsync(model); return(Json(new { isOk = res })); } }
private static Plan UpdateStatus(Plan plan, PlanRepository repo, int status) { plan.LastUpdate = Constants.TotalMilliseconds; plan.Status = status; plan = repo.UpdatePlan(plan, new List <int>() { (int)Constants.PlanField.LastUpdate, (int)Constants.PlanField.Status }); if (plan != null && (status == (int)Constants.WorkflowStatus.Deleted || status == (int)Constants.WorkflowStatus.InPlanned)) { FlightManager.UpdateStatus(plan.Flights, status); } return(plan); }
public static Plan GetPlan(int code) { var user = UserSession.Current.User; if (user != null) { PlanRepository repo = new PlanRepository(false, (int)Constants.PlanAction.Code, code); if (repo.List.Any()) { return(repo.List.FirstOrDefault()); } } throw new Exception(); }
public async Task <JsonResult> SavePlanPoint(PlanPoint model) { using (PlanRepository planRepo = new PlanRepository()) { if (model.num == 0) { var session = Session["CurrentUser"] as CurrentUser; model.PublisherId = session.Sys_User.Uid; } var res = await planRepo.AddOrUpdatePlanPointAsync(model); return(Json(new { isOk = res })); } }
public PlansController() { _plans = new PlanRepository(); _planMapper = new PlanViewModelMapper(); try { _currentUser = System.Web.HttpContext.Current.User.Identity.GetUserId(); } catch (Exception Ex) { _currentUser = null; } }
public void BeforeTest() { var builder = new DbContextOptionsBuilder <PlanContext>(); builder.EnableSensitiveDataLogging(); builder.UseInMemoryDatabase("testplan"); var context = new PlanContext(builder.Options); var repository = new PlanRepository(context); this.controller = new( Mock.Of <ILogger <PlansController> >(), repository); Assert.IsNotNull(this.controller); }
public static void Init() { PathResolver = new PathResolver(System.AppDomain.CurrentDomain.BaseDirectory); UrlResolver = new UrlResolver(ConfigurationManager.AppSettings["RootUrl"]); PlanRepository = new PlanRepository(); if (ConfigurationManager.AppSettings["MockUserAuth"] == "true") { UserAuthenticator = new MockUserAuthenticator(); } else { UserAuthenticator = new ProductionUserAuthenticator(); } }
public void CanPersistPropertyChanges() { var provider = new PlanStorageProviderMonitor(GenerateRefTree()); var cache = new PlanCache(new ExpirationStrategyMock()); var repository = new PlanRepository(new PlanStorage(cache, provider)); repository.GetById <ActivityDO>(NewGuid(2)).Label = "newName"; repository.GetById <ActivityDO>(NewGuid(3)).Label = "newName3"; repository.SaveChanges(); repository = new PlanRepository(new PlanStorage(cache, provider)); Assert.AreEqual("newName", repository.GetById <ActivityDO>(NewGuid(2)).Label, "Labels are different"); Assert.AreEqual("newName3", repository.GetById <ActivityDO>(NewGuid(3)).Label, "Labels are different"); }
public void CanAddPlan() { var provider = new PersistentPlanStorage(null); var cache = new PlanCache(new ExpirationStrategyMock()); var repository = new PlanRepository(new PlanStorage(cache, provider)); var plan = GenerateTestPlan(); repository.Add(plan); repository.SaveChanges(); var loadedPlan = provider.LoadPlan(Guid.Empty); AssertEquals(plan, loadedPlan); AssertEquals(plan, repository.GetById <PlanDO>(NewGuid(13))); }
public static Entidades.ViewModels.DetallePlan GetDetallePlan(int idPlan) { var detalle = new Entidades.ViewModels.DetallePlan(); var planRepo = new PlanRepository(); var plan = planRepo.Filtrar(p => p.Id == idPlan).FirstOrDefault(); if (plan != null) { detalle.Nombre = plan.Nombre; detalle.Id = plan.Id; detalle.Estado = Util.Estados.EstadosUtil.GetEstadoPlan(plan.EstadoPlan); detalle.FechaCreacion = plan.FechaCreacion; detalle.FechaVencimiento = plan.FechaVencimiento; detalle.Vencimiento = plan.Vencimiento; var franquiciaRepo = new Repositorio.Repository.FranquiciaRepository(); var franquicia = franquiciaRepo.GetFranquiciaPorId(plan.FranquiciaId); detalle.FranquiciaId = plan.FranquiciaId; detalle.NombreFranquicia = franquicia.Nombre; var limitacionesRepo = new PlanLimitacionRepository(); var limits = limitacionesRepo.GetLimitacionesPlan(plan.Id); var limitaciones = limits.Select(limitacion => new LimitacionesPlan() { Id = limitacion.Id, Nombre = limitacion.Nombre, Cantidad = limitacion.Cantidad, Periodo = Util.Textos.Periodos.GetPeriodosPlan(limitacion.Periodo) }).ToList(); detalle.LimitacionesPlan = limitaciones; var clientes = new List<ClientePlan>(); detalle.ClientesPlan = clientes; return detalle; } return null; }
public static List<Entidades.ViewModels.PlanesFranquicia> GetPlanesFranquicia(int idFranquicia) { var planes = new List<PlanesFranquicia>(); var planRepo = new PlanRepository(); var limitacionesRepo = new PlanLimitacionRepository(); var planesRepo = planRepo.GetPlanPorFranquicia(idFranquicia); if (planesRepo.Any()) { foreach (var plan in planesRepo) { var limits = limitacionesRepo.GetLimitacionesPlan(plan.Id); var limitaciones = new List<Entidades.ViewModels.LimitacionesPlan>(); foreach (var limitacion in limits) { limitaciones.Add(new LimitacionesPlan() { Id = limitacion.Id, Nombre = limitacion.Nombre, Cantidad = limitacion.Cantidad, Periodo = Util.Textos.Periodos.GetPeriodosPlan(limitacion.Periodo) }); } planes.Add(new PlanesFranquicia() { Id = plan.Id, Nombre = plan.Nombre, Estado = Util.Estados.EstadosUtil.GetEstadoPlan(plan.EstadoPlan), LimitacionesPlan = limitaciones }); } } return planes; }