Beispiel #1
0
        public async Task <IEnumerable <TShirt> > GetAll()
        {
            Console.WriteLine("starting some async task...");

            //Thread.Sleep (100);
            await Task.Delay(100);

            var tshirt = new TShirt();

            tshirt.Id             = 5;
            tshirt.PrintTechnique = "some special technique";
            tshirt.Title          = "some sophisticated title";

            var tshirt2 = new TShirt();

            tshirt2.Id             = 6;
            tshirt2.PrintTechnique = "screen print";
            tshirt2.Title          = "tell your story";

            var tshirts = new List <TShirt>();

            tshirts.Add(tshirt);
            tshirts.Add(tshirt2);

            return(tshirts);
        }
        public async Task <TShirt> Edit(TShirt tshirt)
        {
            // TODO: implement actual implementation

            await Task.Delay(100);

            // TODO: if successfull
            return(tshirt);
        }
		public async Task<TShirt> Edit(TShirt tshirt)
		{
			// TODO: implement actual implementation

			await Task.Delay(100);

			// TODO: if successfull
			return tshirt;
		}
		public async Task<TShirt> Get(int id)
		{
			var tshirt = new TShirt ();
			tshirt.Id = id;
			tshirt.PrintTechnique = "Print technique #" +id.ToString();
			tshirt.Title = "Title #" + id.ToString();

			await Task.Delay (100);

			return tshirt;
		}
Beispiel #5
0
        public async Task <TShirt> Get(int id)
        {
            var tshirt = new TShirt();

            tshirt.Id             = id;
            tshirt.PrintTechnique = "Print technique #" + id.ToString();
            tshirt.Title          = "Title #" + id.ToString();

            await Task.Delay(100);

            return(tshirt);
        }
		public async Task<TShirt> Get(int id)
		{
			// TODO: replace with actual implementation
			var tshirt = new TShirt();
			tshirt.Id = id;
			tshirt.PrintTechnique = "Print technique #" + id.ToString();
			tshirt.Title = "Tshirt #" + id.ToString ();

			await Task.Delay(100);

			return tshirt;
		}
        public async Task <TShirt> Get(int id)
        {
            // TODO: replace with actual implementation
            var tshirt = new TShirt();

            tshirt.Id             = id;
            tshirt.PrintTechnique = "Print technique #" + id.ToString();
            tshirt.Title          = "Tshirt #" + id.ToString();

            await Task.Delay(100);

            return(tshirt);
        }
		public async Task<TShirt> Persist(TShirt tshirt)
		{
			// TODO:
			// replace stubed tshirt with actual one
			var tshirtStub = new TShirt();
			tshirtStub.Id = 5;
			tshirtStub.PrintTechnique = "special technique";
			tshirtStub.Title = "stubed tshirt";

			using (var client = new MyCouchClient("http://localhost:5984", "cshirts")) {
				var response = await client.Entities.PostAsync (tshirtStub);
				Console.WriteLine (response); // TODO: remove WriteLine
			}

			// TODO: if successfull
			return tshirtStub;
		}
        public async Task <TShirt> Persist(TShirt tshirt)
        {
            // TODO:
            // replace stubed tshirt with actual one
            var tshirtStub = new TShirt();

            tshirtStub.Id             = 5;
            tshirtStub.PrintTechnique = "special technique";
            tshirtStub.Title          = "stubed tshirt";

            using (var client = new MyCouchClient("http://localhost:5984", "cshirts")) {
                var response = await client.Entities.PostAsync(tshirtStub);

                Console.WriteLine(response);                  // TODO: remove WriteLine
            }

            // TODO: if successfull
            return(tshirtStub);
        }
		public async Task<IEnumerable<TShirt>> GetAll() {
			Console.WriteLine ("starting some async task...");

			//Thread.Sleep (100);
			await Task.Delay(100);

			var tshirt = new TShirt ();
			tshirt.Id = 5;
			tshirt.PrintTechnique = "some special technique";
			tshirt.Title = "some sophisticated title";

			var tshirt2 = new TShirt ();
			tshirt2.Id = 6;
			tshirt2.PrintTechnique = "screen print";
			tshirt2.Title = "tell your story";

			var tshirts = new List<TShirt>();
			tshirts.Add (tshirt);
			tshirts.Add (tshirt2);

			return tshirts;
		}
		public async Task<IEnumerable<TShirt>> GetAll()
		{
			Task<ViewQueryResponse<TShirt>> tshirtTask;
			ViewQueryResponse<TShirt> tshirtResult;
			List<TShirt> tshirts = null;

			// TODO: inject client or replace client with store
			using (var client = new MyCouchClient("http://localhost:5984", "cshirts")) {
				var query = new QueryViewRequest("getAllTshirts");
				tshirtTask = client.Views.QueryAsync<TShirt>(query);
			}

			tshirtResult = await tshirtTask;

			foreach (var row in tshirtResult.Rows) {				
				var tshirt = new TShirt ();
				tshirt = row.Value;
				tshirts.Add (tshirt);
			}
			Console.WriteLine (tshirts);
			return tshirts;
		}
        public async Task <IEnumerable <TShirt> > GetAll()
        {
            Task <ViewQueryResponse <TShirt> > tshirtTask;
            ViewQueryResponse <TShirt>         tshirtResult;
            List <TShirt> tshirts = null;

            // TODO: inject client or replace client with store
            using (var client = new MyCouchClient("http://localhost:5984", "cshirts")) {
                var query = new QueryViewRequest("getAllTshirts");
                tshirtTask = client.Views.QueryAsync <TShirt>(query);
            }

            tshirtResult = await tshirtTask;

            foreach (var row in tshirtResult.Rows)
            {
                var tshirt = new TShirt();
                tshirt = row.Value;
                tshirts.Add(tshirt);
            }
            Console.WriteLine(tshirts);
            return(tshirts);
        }
		public async Task<TShirt> Edit(TShirt tshirt) {

			await Task.Delay(100);

			return tshirt;
		}
Beispiel #14
0
        public async Task <TShirt> Edit(TShirt tshirt)
        {
            await Task.Delay(100);

            return(tshirt);
        }
Beispiel #15
0
        public HomeModule(ITShirtRepository tshirtRepository)
        {
            // global index view
            Get["/"] = parameters => {
                return View["Index"];
            };

            // return all tshirts
            Get["/tshirts", true] = async (x, ct) => {

                // get "domain" obj
                IEnumerable<TShirt> tshirts = await tshirtRepository.GetAll();

                // prepare tshirtdto list
                var tshirtdtos = new List<TShirtDTO>();

                // convert to dto
                foreach (TShirt tshirt in tshirts)
                {
                    var tshirtdto = new TShirtDTO();
                    tshirtdto.Id = tshirt.Id; // use auto-mapper instead
                    tshirtdto.PrintTechnique = tshirt.PrintTechnique;
                    tshirtdto.Title = tshirt.Title;
                    tshirtdtos.Add(tshirtdto);
                }

                // convert to json
                var tshirtsAsJson = JsonConvert.SerializeObject(tshirtdtos);

                // prepare json
                var response = (Response)tshirtsAsJson;
                response.ContentType = "application/json";

                return response;
            };

            Get["/tshirt/create/"] = parameters => {

                // TODO: find a solution to remove the instance, must have to do with razor..
                // stack trace: I have a create form, which should be bound to a specific model
                // but when calling @Model, I get a System.NullReferenceException
                // I can call the @Model in another view, where I pass an existing instance of the model.
                // Also, I can call the create view, once I remove all @Model statements.
                // I just figured out, passing an empty instance of the model works
                // http://www.jhovgaard.com/from-aspnet-mvc-to-nancy-part-2/
                var tshirt = new TShirtDTO();

                return tshirt;
            };

            Post["/tshirt/create/", true] = async (x, ct) => {

                // bind json to dto
                var tshirtDTO = this.Bind<TShirtDTO>();

                // write dto data to tshirt object
                var tshirt = new TShirt();
                tshirt.Id = tshirtDTO.Id;
                tshirt.PrintTechnique = tshirtDTO.PrintTechnique;
                tshirt.Title = tshirtDTO.Title;

                // persist tshirt object
                var result = await tshirtRepository.Persist(tshirt);

                return result;
                // Redirect user to Index action with a "status" value as a querystring
                // return Response.AsRedirect("");
            };

            Get ["/tshirt/{id}", true] = async (x, ct) => {

                var tshirt = await tshirtRepository.Get(x.id);

                var tshirtDTO = new TShirt();
                tshirtDTO.Id = tshirt.Id;
                tshirtDTO.PrintTechnique = tshirt.PrintTechnique;
                tshirtDTO.Title = tshirt.Title;

                // convert to json
                var tshirtAsJson = JsonConvert.SerializeObject(tshirtDTO);

                // prepare json
                var response = (Response)tshirtAsJson;
                response.ContentType = "application/json";

                return response;
            };

            Post ["/tshirt/{id}/edit", true] = async (x, ct) => {
                var tshirtDTO = this.Bind<TShirtDTO>();

                var tshirt = new TShirt();
                tshirt.Id = tshirtDTO.Id;
                tshirt.PrintTechnique = tshirtDTO.PrintTechnique;
                tshirt.Title = tshirtDTO.Title;

                var response = await tshirtRepository.Edit(tshirt);
                return response;
            };

            Post ["/tshirt/{id}/delete", true] = async (x, ct) => {
                var response = await tshirtRepository.Delete(x.id);
                return response;
            };
        }