Exemple #1
0
 public Employee Get(int Id)
 {
     try
     {
         Employee item = client.ReadDocumentAsync <Employee>(UriFactory.CreateDocumentUri(config.Database, config.EmployeeCollection, Id.ToString()).ToString()).Result;
         return(item);
     }
     catch (AggregateException ae)
     {
         if (ae.InnerException is DocumentClientException &&
             (ae.InnerException as DocumentClientException).StatusCode == System.Net.HttpStatusCode.NotFound)
         {
             return(null);
         }
         throw;
     }
 }
Exemple #2
0
        public void Create(CreateModel model)
        {
            Employee employee = new Employee
            {
                Name      = model.Name,
                Surname   = model.Surname,
                About     = model.About,
                BirthDate = model.BirthDate
            };

            if (model.Image != null)
            {
                string str          = GetHashString(model.Image.FileName);
                string path         = @"\images\" + str + ".jpg";
                string absolutePath = _environment.WebRootPath + path;
                using (var fileStream = new FileStream(absolutePath, FileMode.Create))
                {
                    model.Image.CopyTo(fileStream);
                }
                employee.ImageLocation = path;
            }
            client.CreateDocumentAsync(collectionUri, employee).Wait();
        }