public WebSocketMiddleware(RequestDelegate next,
                            IMessageReceiver receiver, IMyContext context)
 {
     _next            = next;
     _messageReceiver = receiver;
     _myContext       = context;
 }
示例#2
0
        public TimeEntryModule(IMyContext ctx) : base("/recordTime")
        {
            Post["/{projectid}"] = _ =>
            {
                TimeEntry newEntry  = this.Bind();
                int       projectId = _.projectid; // Need to cast the parameter to int so LINQ knows its working with the correct type
                newEntry.Project          = ctx.Projects.Find(projectId);
                newEntry.RegistrationDate = DateTime.Now;
                ctx.TimeEntries.Add(newEntry);
                ctx.SaveChanges();

                return(Response.AsJson <object>(newEntry));
            };

            Post["/del/{id}"] = x =>
            {
                var entry = new TimeEntry()
                {
                    Id = x.id
                };
                ctx.Entry(entry).State = EntityState.Deleted;

                ctx.SaveChanges();

                return(Response.AsText("Time entry successfully deleted"));
            };
        }
示例#3
0
        public MessageReceiver(IDbRepository db, IMyContext myContext, MessageSenderFactory senderFactory, Searcher searcher)
        {
            _myContext = myContext;
            _db        = db;
            _sender    = senderFactory.Create(_myContext.SocketDisconnected);
            _searcher  = searcher;

            _responseFunctions = Mapper.BuildResponseFunctions(this);
        }
示例#4
0
 public NotifyController(
     IEmailSender mailSenderService,
     IMyContext context,
     IHostingEnvironment env,
     ISessionService sessionContext)
 {
     emailSender        = mailSenderService;
     dbContext          = context;
     hostingEnvironment = env;
     session            = sessionContext;
 }
        public AggregateServiceFixture()
        {
            _someDependencyMock = new Mock<ISomeDependency>().Object;

            var builder = new ContainerBuilder();
            builder.RegisterAggregateService<IMyContext>();
            builder.RegisterType<MyServiceImpl>()
                .As<IMyService>()
                .InstancePerDependency();
            builder.RegisterInstance(_someDependencyMock);
            _container = builder.Build();

            _aggregateService = _container.Resolve<IMyContext>();
        }
示例#6
0
        public AggregateServiceFixture()
        {
            _someDependencyMock = new Mock <ISomeDependency>().Object;

            var builder = new ContainerBuilder();

            builder.RegisterAggregateService <IMyContext>();
            builder.RegisterType <MyServiceImpl>()
            .As <IMyService>()
            .InstancePerDependency();
            builder.RegisterInstance(_someDependencyMock);
            _container = builder.Build();

            _aggregateService = _container.Resolve <IMyContext>();
        }
示例#7
0
        public DinnerModule(IMyContext ctx) : base("/dinner")
        {
            Get["/"] = x =>
            {
                return(Response.AsJson <object>(ctx.Dinners.ToArray()));
            };

            Post["/"] = _ =>
            {
                Dinner dinner = this.Bind <Dinner>();

                ctx.Dinners.Add(dinner);
                ctx.SaveChanges();

                return(HttpStatusCode.OK);
            };

            Put["/{id:int}"] = parameters =>
            {
                Dinner dinner = this.Bind <Dinner>();

                dinner.Id = parameters.id;
                ctx.Dinners.Attach(dinner);
                ctx.Entry(dinner).State = EntityState.Modified;
                ctx.SaveChanges();

                return(HttpStatusCode.OK);
            };

            Delete["/{id:int}"] = x =>
            {
                var dinner = new Dinner()
                {
                    Id = x.id
                };
                ctx.Entry(dinner).State = EntityState.Deleted;

                ctx.SaveChanges();

                return(HttpStatusCode.OK);
            };
        }
示例#8
0
        public string MakeResponse(IMyContext db, string[] request)
        {
            var repeatedItem = new Tuple <int, string>(3, "café");
            var pedidoAux    = request.Skip(1).OrderBy(x => x).ToArray();
            var result       = "";

            Array.Sort((Array)pedidoAux);
            var repeatedQuantity = 1;

            for (var i = 1; i < request.Length; i++)
            {
                request[i] = pedidoAux[i - 1];

                var typeId          = Convert.ToInt16(request[i]);
                var mealDescription = db.GetMealDescription(typeId, Period.Id);

                if (!result.Contains(mealDescription))
                {
                    if (mealDescription == "erro")
                    {
                        result += ", ";
                    }
                    result += mealDescription;
                }
                else if (repeatedItem.Item1 == typeId)
                {
                    repeatedQuantity++;
                }

                if (i > 0 && typeId != repeatedItem.Item1)
                {
                    result += ", ";
                }
                else if (typeId == repeatedItem.Item1 && !result.Contains(mealDescription))
                {
                    result += ", ";
                }
            }

            return(FormatResult(result, repeatedItem, repeatedQuantity));
        }
示例#9
0
        public virtual IMeal CreateMeal(IMyContext db, string period)
        {
            IMeal meal = null;

            switch (period)
            {
            case "manhã":
            case "manha":
                meal = new DayMeal(db);
                break;

            case "noite":
                meal = new NightMeal(db);
                break;

            default:
                throw new ArgumentException("Pedido inválido");
            }

            return(meal);
        }
 public UnitOfWork()
 {
     context = new MyContext();
 }
示例#11
0
 public PersonRepository(IMyContext context) : base(context)
 {
 }
示例#12
0
 /// <summary>
 /// Initializes a new instance of the RepositoryContext class with context.
 /// </summary>
 /// <param name="emsContext">Database context.</param>
 public RepositoryContext(IMyContext emsContext)
 {
     databaseContext = emsContext;
 }
示例#13
0
        public ClientModule(IMyContext ctx) : base("/clients")
        {
            Get["/list"] = parameters =>
            {
                var model = new ResponseBean()
                {
                    Clients = ctx.Clients.ToList()
                };
                return(View["ListClients", model]);
            };

            Get["/create"] = parameters =>
            {
                return(View["CreateClient"]);
            };

            Post["/create"] = _ =>
            {
                var message       = "Successfully added client ";
                var createSuccess = "alert-success";
                try
                {
                    var client = this.Bind <Client>();
                    client.CreationDate = DateTime.Now;

                    ctx.Clients.Add(client);
                    ctx.SaveChanges();
                    message += " " + client.CompanyName;
                }
                catch (Exception ex)
                {
                    if (ex is ModelBindingException)
                    {
                        message = "Couldn't bind model. <br>" +
                                  HtmlUtil.FormatExceptionHtml(ex);
                        createSuccess = "alert-warning";
                    }
                    else if (ex is DbUpdateException || ex is RequestExecutionException)
                    {
                        message = "Couldn't complete request to DataBase. <br>" +
                                  HtmlUtil.FormatExceptionHtml(ex);
                        createSuccess = "alert-danger";
                    }
                    else
                    {
                        message = "Something went wrong while creating your project :/<br>" +
                                  HtmlUtil.FormatExceptionHtml(ex);

                        createSuccess = "alert-danger";
                    }
                }
                var model = new ResponseBean()
                {
                    Message = message, CreateSuccess = createSuccess, Redirect = true
                };
                return(View["CreateClient", model]);
            };

            Get["/{id}"] = _ =>
            {
                ResponseBean model = new ResponseBean();
                Client       c;
                int          clientId = _.id;
                if ((c = ctx.Clients.Find(clientId)) != null)
                {
                    model.Client = c;
                    var projects = ctx.Projects.Where(p => p.Client.Id == clientId).ToList();
                    model.Projects = projects;
                    model.Success  = true; // We need to send a bool, since the SSVE @If can only check on bools
                }
                else
                {
                    model.Message = "Couldn't find client with id " + _.id;
                    model.Success = false;
                }
                return(View["ClientDetail", model]);
            };
        }
示例#14
0
 /// <summary>
 /// Initializes a new instance of the BaseRepository class for specific database context.
 /// </summary>
 /// <param name="context">Database context.</param>
 protected BaseRepository(IMyContext context)
 {
     MyContext    = context;
     shareContext = true;
 }
示例#15
0
 public ArticleRepository(IMyContext context)
 {
     _ctx = context;
 }
示例#16
0
 public NightMeal(IMyContext db)
 {
     Period = db.GetFirstPeriod("noite");
 }
示例#17
0
 public UserRepository(IMyContext context)
     : base(context)
 {
 }
 public MyController(IMyContext context)
 {
     _context = context;
 }
示例#19
0
 public DayMeal(IMyContext db)
 {
     Period = db.GetFirstPeriod("manhã");
 }
示例#20
0
 /// <summary>
 /// Initializes a new instance of the UserRepository class with context.
 /// </summary>
 /// <param name="objectContext">Database context.</param>
 public UserRepository(IMyContext objectContext)
     : base(objectContext)
 {
 }
示例#21
0
        public ProjectModule(IMyContext ctx)
            : base("/projects")
        {
            Get["/list"] = parameters =>
            {
                var model = new ResponseBean(ctx.Projects.ToList());
                return(View["ListProjects", model]);
            };

            Get["/create"] = parameters =>
            {
                var clients = new ResponseBean()
                {
                    Clients = ctx.Clients.ToList()
                };
                return(View["CreateProject", clients]);
            };

            Post["/create"] = _ =>
            {
                var message       = "Successfully added project ";
                var createSuccess = "alert-success";
                try
                {
                    string reqString = this.Request.Body.ReadAsString();
                    int    clientId  = getClientIdFromRequest(reqString);
                    var    client    = ctx.Clients.Find(clientId);
                    var    project   = this.Bind <Project>("Client");
                    project.CreationDate = DateTime.Now;
                    project.Client       = client;

                    ctx.Projects.Add(project);
                    ctx.SaveChanges();
                    message += project.Title;
                }
                catch (Exception ex)
                {
                    if (ex is ModelBindingException)
                    {
                        message = "Couldn't bind model. <br>" +
                                  HtmlUtil.FormatExceptionHtml(ex);
                        createSuccess = "alert-warning";
                    }
                    else if (ex is DbUpdateException || ex is RequestExecutionException)
                    {
                        message = "Couldn't complete request to DataBase. <br>" +
                                  HtmlUtil.FormatExceptionHtml(ex);
                        createSuccess = "alert-danger";
                    }
                    else
                    {
                        message = "Something went wrong while creating your project :/<br>" +
                                  HtmlUtil.FormatExceptionHtml(ex);

                        createSuccess = "alert-danger";
                    }
                }
                var model = new ResponseBean()
                {
                    Message       = message,
                    CreateSuccess = createSuccess,
                    Redirect      = true,
                    Clients       = ctx.Clients.ToList()
                };
                return(View["CreateProject", model]);
            };

            Get["/{id}"] = _ =>
            {
                ResponseBean model = new ResponseBean();
                Project      p;
                int          projectId = _.id;
                if ((p = ctx.Projects.Find(projectId)) != null)
                {
                    model.Project = p;
                    model.Client  = p.Client;
                    var   timeEntries = ctx.TimeEntries.Where(t => t.Project.Id == projectId).ToList();
                    float hoursSpent  = timeEntries.Sum(t => t.HoursSpent);
                    model.WorkDone   = timeEntries;
                    model.HoursSpent = hoursSpent;
                    model.Success    = true;  // We need to send a bool, since the SSVE @If can only check on bools
                }
                else
                {
                    model.Message = "Couldn't find project with id " + _.id;
                    model.Success = false;
                }
                return(View["ProjectDetail", model]);
            };

            Post["/del/{id}"] = x =>
            {
                var project = new Project()
                {
                    Id = x.id
                };
                ctx.Entry(project).State = EntityState.Deleted;

                ctx.SaveChanges();

                return(HttpStatusCode.OK);
            };
        }
 public MyAuthorizationFilter(IMyContext context)
 {
     this.context = context;
 }
 public UnitOfWork(IMyContext context)
 {
     this.context = context;
 }
 public SampleQueryHandler(IMyContext context)
 {
     _context = context;
 }
示例#25
0
 public AuthorRepository(IMyContext context)
 {
     _ctx = context;
 }