예제 #1
0
        public async Task <IActionResult> Checkout()
        {
            var cart = GetCart();

            var request = new OrderRequest
            {
                Id       = Guid.NewGuid(),
                Customer = new Models.Orders.Customer
                {
                    FirstName  = "Jane",
                    MiddleName = "Mary",
                    LastName   = "Doe"
                },
                Items = cart.Items.Select(li => new Models.Orders.LineItem
                {
                    ProductId   = li.Key,
                    Quantity    = li.Value.Quantity,
                    ListPrice   = li.Value.ListPrice,
                    ProductName = li.Value.ProductName
                }).ToList(),
                Status = Status.New
            };

            var doc = await _docDbRepository.CreateItemAsync(request);

            cart.Items.Clear();

            HttpContext.Session.Set("Cart", cart);

            return(RedirectToPage("/Orders/Show", new { id = doc.Id }));
        }
예제 #2
0
        public async Task <string> AddAsync(Invoice invoice)
        {
            //add validation here
            var doc = await Repository.CreateItemAsync(invoice);

            return(doc.Id);
        }
        public async Task <Journey> CreateAsync(Journey item, HttpRequestMessage req)
        {
            var config = await _configRepository.GetItemAsync(Config.ConfigId);

            await _configRepository.UpdateItemAsync(config.id, config, req);

            if (item.DropoffAddress == null && (item.DropoffLatitude != null && item.DropoffLongitude != null))
            {
                var result = await "http://dev.virtualearth.net/REST/v1/Locations"
                             .AppendPathSegment(item.DropoffLatitude.ToString() + "," + item.DropoffLongitude.ToString())
                             .SetQueryParams(new { o = "json" })
                             .SetQueryParams(new { key = _applicationConfig.BingMapsAPI })
                             .GetJsonAsync <Location>();
                item.DropoffAddress = new Address()
                {
                    Name         = result.resourceSets[0].resources[0].address.Name,
                    AddressLine1 = result.resourceSets[0].resources[0].address.AddressLine1,
                    AddressLine2 = result.resourceSets[0].resources[0].address.AddressLine2,
                    TownCity     = result.resourceSets[0].resources[0].address.TownCity,
                    County       = result.resourceSets[0].resources[0].address.County,
                    Postcode     = result.resourceSets[0].resources[0].address.Postcode
                };
                // http://dev.virtualearth.net/REST/v1/Locations/47.64054,-122.12934?o=xml&key=BingMapsKey
            }

            return(await _JourneyRepository.CreateItemAsync(item, req));
        }
 public async Task <IActionResult> CreateAsync(Item item)
 {
     if (ModelState.IsValid)
     {
         await Respository.CreateItemAsync(item);
     }
     return(Ok(item));
 }
        public IActionResult Post([FromBody] Quotes value)
        {
            Random r = new Random();

            value.QuoteAmount = r.Next(600, 6000);
            var quote = Respository.CreateItemAsync(value).Result;

            return(Ok(quote));
        }
예제 #6
0
        public async Task <ActionResult <Book> > CreateAsync(BookDTO item)
        {
            var itemModel = _mapper.Map <Book>(item);
            var retModel  = await _documentDBRepository.CreateItemAsync(itemModel);

            var getLink = _linkGenerator.GetPathByAction("GetEntityAsync", "Books", new { Id = retModel.Id });

            return(Created(getLink, retModel));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Completed,Category")] Item item)
        {
            if (ModelState.IsValid)
            {
                await _repo.CreateItemAsync(item);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(item));
        }
예제 #8
0
        public async Task <string> Post([FromBody] Item value)
        {
            var json = JsonConvert.SerializeObject(value);

            logger.LogInformation(LoggingEvents.INSERT_ITEM, "json: {0}", json);

            string id = await repo.CreateItemAsync(value);

            return(id);
        }
        public IActionResult Post([FromBody] ProductModel model)
        {
            model.createdDate  = System.DateTime.Now.ToShortDateString();
            model.modifiedDate = System.DateTime.Now.ToShortDateString();
            model.createdBy    = HttpContext.User.Identity.Name;
            model.modifiedBy   = HttpContext.User.Identity.Name;
            var product = _repo.CreateItemAsync(model, collectionId).Result;

            return(Ok(product));
        }
예제 #10
0
        public IActionResult Post([FromBody] UserDetailsModel per)
        {
            per.createdDate  = System.DateTime.Now.ToShortDateString();
            per.modifiedDate = System.DateTime.Now.ToShortDateString();
            per.createdBy    = HttpContext.User.Identity.Name;
            per.modifiedBy   = HttpContext.User.Identity.Name;
            var user = _repo.CreateItemAsync(per, collectionId).Result;

            return(Ok(user));
        }
예제 #11
0
        public IActionResult CreateLifter([FromBody] LifterModel lifter)
        {
            if (lifter == null)
            {
                return(BadRequest());
            }
            var lifterToReturn = _repository.CreateItemAsync(lifter).Result;

            return(CreatedAtRoute("GetLifter", new { id = lifterToReturn.Id }, lifterToReturn));
        }
        public async Task <IActionResult> CreateAsync(Invoice invoice)
        {
            if (ModelState.IsValid)
            {
                await Repository.CreateItemAsync(invoice);

                return(RedirectToAction("Index"));
            }

            return(View(invoice));
        }
        public async Task <ActionResult> CreateAsync([Bind("personId, PersonType, FirstName, MiddleName, LastName, Address, Email")] Person item)
        {
            if (ModelState.IsValid)
            {
                await _repository.CreateItemAsync(item);

                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
        public async Task <ActionResult> Post([Bind("Id, PersonType, FirstName, MiddleName, LastName, Address, Email")] Person person)
        {
            if (ModelState.IsValid)
            {
                var newPerson = await _repository.CreateItemAsync(person);

                return(Ok((Person)(dynamic)newPerson));
            }

            return(View(person));
        }
예제 #15
0
        public async Task <ActionResult> CreateAsync([Bind("Id,Name,Description,Completed")] Item item)
        {
            if (ModelState.IsValid)
            {
                await _repository.CreateItemAsync(item);

                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
예제 #16
0
        public async Task <ActionResult> CreateAsync([Bind("Date,Column1,Column2,Column3,Column4,Column5,Column6,Bonus")] ResultatJsonFormat item)
        {
            if (ModelState.IsValid)
            {
                await Respository.CreateItemAsync(item);

                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
예제 #17
0
        public async Task <User> CreateUser(User newUser)
        {
            newUser.Frequency = new UserFrequency()
            {
                Frequency = Enums.MessageFrequency.Day
            };

            var document = await userRepository.CreateItemAsync(newUser);

            newUser.Id = document.Id;
            return(newUser);
        }
예제 #18
0
        public async Task <ActionResult> CreateAsync([Bind("Id,Name,Description,Completed")] Item item)
        {
            if (ModelState.IsValid)
            {
                item.Id = Guid.NewGuid().ToString();
                await respository.CreateItemAsync(item);

                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
        public IActionResult CreateLift(Lift lift)
        {
            Lift liftToAdd = new Lift
            {
                Type       = "lift",
                Name       = lift.Name,
                TypeOfLift = lift.TypeOfLift,
                Difficulty = lift.Difficulty,
                WeeklySets = new WeeklySet[0]
            };
            var liftToReturn = _repository.CreateItemAsync(liftToAdd).Result;

            return(RedirectToAction(nameof(Index)));
        }
예제 #20
0
        //public async void PostEVSpecs([FromBody]EVSpecs bev)
        public async Task <IActionResult> PostEVSpecs([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "BEV/PostEVSpecs")] HttpRequest request)

        {
            var body = await request.ReadAsStringAsync();

            EVSpecs?bev = JsonConvert.DeserializeObject <EVSpecs>(body);

            if (bev == null)
            {
                return(NoContent());
            }
            bev.Id = Guid.NewGuid().ToString();
            await respository.CreateItemAsync(bev);

            return(Ok());
        }
        public async Task <bool> Post([FromBody] Employee employee)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    employee.Id = null;
                    await Respository.CreateItemAsync(employee, CollectionId);

                    await _hubContext.Clients.All.BroadcastMessage();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #22
0
        public IActionResult Create(LifterModel lifter)
        {
            LifterModel lifterToAdd = new LifterModel
            {
                Type           = "lifter",
                Name           = lifter.Name,
                Gender         = lifter.Gender,
                Age            = lifter.Age,
                Weight         = lifter.Weight,
                LiftingNumbers = new LiftingNumbersModel
                {
                    Squat    = lifter.LiftingNumbers.Squat,
                    Bench    = lifter.LiftingNumbers.Bench,
                    Deadlift = lifter.LiftingNumbers.Deadlift
                }
            };
            var lifterToReturn = _repository.CreateItemAsync(lifterToAdd).Result;

            return(RedirectToAction(nameof(Details), new { id = lifterToReturn.Id }));
        }
예제 #23
0
        public async Task CreateMockCustomers()
        {
            //Create new customer only if there is none
            //var count = customerRepository.GetItemsCount();
            var mockCustomer = await customerRepository.GetItemsAsync(c => c.ContactName == "Mohamed Saif");

            if (mockCustomer == null || mockCustomer.Count() == 0)
            {
                var cust = new User
                {
                    AccountId   = "A9876-543210",
                    AccountType = "Employee",
                    Address     = new Location
                    {
                        City              = "Dubai",
                        Country           = "UAE",
                        CreatedAt         = DateTime.UtcNow,
                        Id                = Guid.NewGuid().ToString(),
                        FirstLineAddress  = "8th Street",
                        IsDeleted         = false,
                        Point             = new Point(25.2519659, 55.330614),
                        SecondLineAddress = "Dubai Deira City Center",
                        ZipCode           = "1234"
                    },
                    //DigitalIdentity = new DigitalId {   },
                    AuthenticationOptions = "ADB2C",
                    DisplayName           = "Mohamed Saif",
                    CompanyName           = "Contoso",
                    ContactName           = "Mohamed Saif",
                    ContactNumber         = "+9711234567",
                    CreatedAt             = DateTime.UtcNow,
                    Email        = "*****@*****.**",
                    FacePersonId = "059d9c59-81c1-4bb1-96ba-244ee931a8a2", //TODO: Improve FacePersonId settings to be easily updated
                    Id           = "4f93adac-13c6-4fe6-b625-afe7b7431fa1",
                    IsDeleted    = false,
                    Website      = "http://blog.mohamedsaif.com"
                };

                await customerRepository.CreateItemAsync(cust);
            }
        }
예제 #24
0
        public async Task <IActionResult> PutContact([HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "Contact/PutContact")] HttpRequest request)
        {
            var body = await request.ReadAsStringAsync();

            Contact?contact = JsonConvert.DeserializeObject <Contact>(body);

            if (contact == null)
            {
                return(NoContent());
            }
            contact.Id = Guid.NewGuid().ToString();
            if (contact.Password.Length > 0)
            {
                var h = new PasswordHasher <Contact>();
                contact.HashedPassword = h.HashPassword(contact, contact.Password);
                contact.Password       = "";
                contact.DateUpdated    = DateTime.Now;
            }

            await repository.CreateItemAsync(contact);

            return(Ok());
        }
예제 #25
0
        public async Task <SavedFile> AddFileAsync(Stream fileStream, string documentId, string fileName, string name, HttpRequestMessage req)
        {
            if (string.IsNullOrEmpty(documentId))
            {
                documentId = Guid.NewGuid().ToString();
            }

            var SavedFile = new SavedFile()
            {
                name       = string.IsNullOrEmpty(name) ? fileName : name,
                fileName   = fileName,
                documentId = documentId,
            };

            SavedFile = await _SavedFileRepository.CreateItemAsync(SavedFile, req);

            var resourceResponse = await _SavedFileRepository.AddAttachment(SavedFile.id, fileStream, "application/octet-stream", SavedFile.fileName);

            SavedFile.attachmentId = resourceResponse.Resource.Id;
            SavedFile = await _SavedFileRepository.UpdateItemAsync(SavedFile.id, SavedFile, req);

            return(SavedFile);
        }
        public IActionResult Post([FromBody] Registrations value)
        {
            var registration = Respository.CreateItemAsync(value).Result;

            return(Ok(registration));
        }
        public static async Task <NewRequest <SmartDoc> > CreateNewRequest(
            string ownerId,
            bool isAsync,
            IFormFile doc,
            ClassificationType docType,
            IStorageRepository storageRepository,
            IDocumentDBRepository <SmartDoc> docRepository,
            IDocumentDBRepository <User> userRepository)
        {
            if (doc == null || doc.Length == 0)
            {
                throw new InvalidOperationException("No file was selected");
            }

            var owner = await userRepository.GetItemAsync(ownerId);

            if (owner == null)
            {
                throw new InvalidOperationException("Invalid request");
            }

            long size = doc.Length;

            // To hold the Url for the uploaded document
            string docName = "NA";
            string docUri  = null;

            //Upload the submitted document to Azure Storage
            if (size > 0)
            {
                using (var stream = doc.OpenReadStream())
                {
                    var docExtention = doc.FileName.Substring(doc.FileName.LastIndexOf('.'));
                    var docId        = Guid.NewGuid();
                    docName = $"{docType}-{docId}{docExtention}";
                    docUri  = await storageRepository.CreateFile(docName, stream);
                }
            }


            // process uploaded files by creating a new SmartDoc record with the details and save it to CosmosDB
            var newDoc = new SmartDoc
            {
                Id        = Guid.NewGuid().ToString(),
                OwnerId   = ownerId,
                DocType   = docType,
                CreatedAt = DateTime.UtcNow,
                IsDeleted = false,
                DocName   = docName,
                DocUrl    = docUri,
                Status    = SmartDocStatus.Created.ToString(),
                Origin    = docRepository.Origin
            };

            await docRepository.CreateItemAsync(newDoc);

            //Prepare the new request that will hold the document along with the processing instructions by the Cognitive Pipeline
            var newReq = new NewRequest <SmartDoc>
            {
                CreatedAt       = DateTime.UtcNow,
                Id              = Guid.NewGuid().ToString(),
                OwnerId         = ownerId,
                IsDeleted       = false,
                Instructions    = DocumentInstructionsProcessor.GetInstructions(docType),
                ItemReferenceId = newDoc.Id,
                RequestItem     = newDoc,
                Status          = SmartDocStatus.Created.ToString(),
                Origin          = docRepository.Origin,
                IsAsync         = isAsync
            };

            return(newReq);
        }
예제 #28
0
        public async Task <IActionResult> SubmitDoc(string ownerId, string docType, bool isAsync, IFormFile doc)
        {
            // TODO: Introduce another parameter to identify the needed classification services (like classification, OCR,...)

            if (doc == null || doc.Length == 0)
            {
                return(BadRequest("file not selected"));
            }

            var owner = await userRepository.GetItemAsync(ownerId);

            if (owner == null)
            {
                return(BadRequest("Invalid request"));
            }

            var proposedDocType = ClassificationType.Unidentified;
            var isValidType     = Enum.TryParse <ClassificationType>(docType, out proposedDocType);

            if (!isValidType)
            {
                return(BadRequest("Invalid document type"));
            }

            long size = doc.Length;

            // full path to file in temp location
            string docName = "NA";
            string docUri  = null;

            if (size > 0)
            {
                using (var stream = doc.OpenReadStream())
                {
                    var docExtention = doc.FileName.Substring(doc.FileName.LastIndexOf('.'));
                    var docId        = Guid.NewGuid();
                    docName = $"{proposedDocType}-{docId}{docExtention}";
                    docUri  = await storageRepository.CreateFile(docName, stream);
                }

                //Sample to upload to local temp storage
                //var tempFolder = Path.GetTempPath();
                //var fileName = Path.GetRandomFileName();
                //var filePath = Path.Combine(tempFolder, fileName);
                //using (var stream = new FileStream(filePath, FileMode.Create))
                //{
                //    await doc.CopyToAsync(stream);
                //}
            }


            // process uploaded files
            // Don't rely on or trust the FileName property without validation.
            var newDoc = new SmartDoc
            {
                Id        = Guid.NewGuid().ToString(),
                OwnerId   = ownerId,
                DocType   = proposedDocType,
                CreatedAt = DateTime.UtcNow,
                IsDeleted = false,
                DocName   = docName,
                DocUrl    = docUri,
                Status    = SmartDocStatus.Created.ToString(),
                Origin    = docRepository.Origin
            };

            await docRepository.CreateItemAsync(newDoc);

            //Call NewReq function background service to start processing the new doc
            var newReq = new NewRequest <SmartDoc>
            {
                CreatedAt       = DateTime.UtcNow,
                Id              = Guid.NewGuid().ToString(),
                OwnerId         = ownerId,
                IsDeleted       = false,
                Instructions    = DocumentInstructionsProcessor.GetInstructions(proposedDocType),
                ItemReferenceId = newDoc.Id,
                RequestItem     = newDoc,
                Status          = SmartDocStatus.Created.ToString(),
                Origin          = docRepository.Origin,
                IsAsync         = isAsync
            };

            var result = await newReqService.SendNewRequest(newReq, newDoc.Id, isAsync);

            return(Ok(result));
        }
예제 #29
0
        public IActionResult Post([FromBody] Issues value)
        {
            var issue = Respository.CreateItemAsync(value).Result;

            return(Ok(issue));
        }
예제 #30
0
        public async Task <Vehicle> CreateAsync(Vehicle item, HttpRequestMessage req)
        {
            var createResult = await _organisationRepository.CreateItemAsync(item, req);

            return(createResult);
        }