public async Task <IActionResult> PutCompany([FromRoute] int id, [FromBody] Company company)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != company.CompanyId)
            {
                return(BadRequest());
            }

            _context.Entry(company).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CompanyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #2
0
        public async Task <IActionResult> Put(int id, Company Company)
        {
            if (id != Company.Id)
            {
                return(BadRequest());
            }

            _context.Entry(Company).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CompanyExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #3
0
        public async Task <IActionResult> PutManager([FromRoute] int id, [FromBody] Manager manager)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != manager.ManagerID)
            {
                return(BadRequest());
            }

            _context.Entry(manager).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ManagerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #4
0
        public async Task <IActionResult> PutDepartment(int id, DepartmentDTO departmentDTO)
        {
            if (id != departmentDTO.DepartmentId)
            {
                return(BadRequest());
            }

            _context.Entry(DTOToDepartment(departmentDTO)).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DepartmentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Пример #5
0
 public async Task <IActionResult> PutEmployee(int id, EmployeeDTO employeeDTO)
 {
     if (id != employeeDTO.EmployeeId)
     {
         return(BadRequest());
     }
     _context.Entry(DTOToEmployee(employeeDTO)).State =
         EntityState.Modified;
     try
     {
         await _context.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!EmployeeExists(id))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(NoContent());
 }
Пример #6
0
 /// <summary>
 /// Overwrites an existing record in database with given one.
 /// </summary>
 /// <param name="updatedRecord">Previously modified object.</param>
 /// <returns></returns>
 public async Task UpdateRecordAsync(T updatedRecord)
 {
     using (var companyDb = new CompanyDbContext())
     {
         companyDb.Entry(updatedRecord).State = EntityState.Modified;
         await companyDb.SaveChangesAsync().ConfigureAwait(false);
     }
 }
Пример #7
0
 public ActionResult Edit([Bind(Include = "UserGroupID,RoleID")] Credential credential)
 {
     if (ModelState.IsValid)
     {
         db.Entry(credential).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(credential));
 }
Пример #8
0
 public ActionResult Edit([Bind(Include = "ID,Text,Link,DisplayOrder,Target,Status,TypeID")] Menu menu)
 {
     if (ModelState.IsValid)
     {
         db.Entry(menu).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(menu));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,Phone,Email,Address,CreateDate,CreateBy,ModifiedDate,ModifiedBy,Content,Status")] Feedback feedback)
 {
     if (ModelState.IsValid)
     {
         db.Entry(feedback).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(feedback));
 }
Пример #10
0
        /// <summary>
        /// Resets assigned employee of specified room key to null value.
        /// </summary>
        /// <param name="key">Target room key.</param>
        /// <returns></returns>
        public async Task TakeTheRoomKeyAsync(RoomKey key)
        {
            using (CompanyDbContext companyDb = new CompanyDbContext())
            {
                key.ChangeAssignedEmployee(null);
                companyDb.Entry(key).State = EntityState.Modified;

                await companyDb.SaveChangesAsync().ConfigureAwait(false);
            }
        }
 public ActionResult Edit([Bind(Include = "ID,Content,Status")] Footer footer)
 {
     if (ModelState.IsValid)
     {
         db.Entry(footer).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(footer));
 }
 public ActionResult Edit([Bind(Include = "ID,Name")] MenuType menuType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(menuType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(menuType));
 }
Пример #13
0
 public ActionResult Edit([Bind(Include = "ID,Image,DisplayOrder,Link,Description,CreateDate,CreateBy,ModifiedDate,ModifiedBy,Status")] Slide slide)
 {
     if (ModelState.IsValid)
     {
         db.Entry(slide).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(slide));
 }
 public ActionResult Edit([Bind(Include = "ID,Name,Description,Detail,Image,CreateDate,CreateBy,ModifiedDate,ModifiedBy,Status")] About about)
 {
     if (ModelState.IsValid)
     {
         db.Entry(about).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(about));
 }
Пример #15
0
 public ActionResult Edit([Bind(Include = "ID,Name,Description,Detail,Status,CreateDate,CreateBy,ModifiedDate,ModifiedBy,ShowOnHome")] CategoryNew categoryNew)
 {
     if (ModelState.IsValid)
     {
         db.Entry(categoryNew).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(categoryNew));
 }
Пример #16
0
        public IActionResult Delete(Guid id)
        {
            var obj = new ProductComponents {
                Id = id
            };

            context.Entry(obj).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            context.SaveChanges();

            return(Ok());
        }
Пример #17
0
 public ActionResult Edit([Bind(Include = "ID,Name,Description,Image,Detail,Status,CreateDate,CreateBy,ModifiedDate,ModifiedBy,CategoryServicesID")] Service service)
 {
     if (ModelState.IsValid)
     {
         SetViewBag(service.CategoryServicesID);
         service.ModifiedDate    = DateTime.Now;
         db.Entry(service).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(service));
 }
Пример #18
0
 /// <summary>
 /// Resets assigned employee of room keys collection to null value.
 /// </summary>
 /// <param name="keys">Target collection of room keys.</param>
 /// <returns></returns>
 public async Task TakeMultipleRoomKeysAsync(IEnumerable <RoomKey> keys)
 {
     using (CompanyDbContext companyDb = new CompanyDbContext())
     {
         foreach (RoomKey key in keys)
         {
             key.ChangeAssignedEmployee(null);
             companyDb.Entry(key).State = EntityState.Modified;
         }
         await companyDb.SaveChangesAsync().ConfigureAwait(false);
     }
 }
Пример #19
0
        public Employee UpdateEmployee(Employee employee)
        {
            var result = context.Employees.FirstOrDefault(e => e.Id == employee.Id);

            if (result == null)
            {
                return(null);
            }

            context.Entry(result).CurrentValues.SetValues(employee);
            context.SaveChanges();

            return(employee);
        }
Пример #20
0
        public IActionResult EditEmployee(Employee updatedEmployee)
        {
            Employee dbEmployee = _context.Employees.Find(updatedEmployee.Id);

            if (ModelState.IsValid)
            {
                dbEmployee.FirstName = updatedEmployee.FirstName;
                dbEmployee.LastName  = updatedEmployee.LastName;
                dbEmployee.Email     = updatedEmployee.Email;

                _context.Entry(dbEmployee).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                _context.Update(dbEmployee);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Пример #21
0
        public IActionResult UpdateDepartment(Department newDepartment)
        {
            if (ModelState.IsValid)
            {
                Department oldDepartment = _context.Departments.Find(newDepartment.DepartmentId);
                oldDepartment.Name     = newDepartment.Name;
                oldDepartment.Location = newDepartment.Location;
                oldDepartment.Budget   = newDepartment.Budget;
                oldDepartment.Type     = newDepartment.Type;

                _context.Entry(oldDepartment).State = Microsoft.EntityFrameworkCore.EntityState.Modified;

                _context.Update(oldDepartment);
                _context.SaveChanges();
            }
            return(RedirectToAction("DepartmentIndex"));
        }
Пример #22
0
        public IActionResult EditDepartment(Department updatedDepartment)
        {
            Department dbDepartment = _context.Departments.Find(updatedDepartment.Id);

            if (ModelState.IsValid)
            {
                dbDepartment.Name     = updatedDepartment.Name;
                dbDepartment.Location = updatedDepartment.Location;
                dbDepartment.Type     = updatedDepartment.Type;
                dbDepartment.Budget   = updatedDepartment.Budget;

                _context.Entry(dbDepartment).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                _context.Update(dbDepartment);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Пример #23
0
        public int Edit(News content)
        {
            try
            {
                if (string.IsNullOrEmpty(content.MetaTitle))
                {
                    content.MetaTitle = StringHelper.ToUnsignString(content.Name);
                }
                content.ModifiedDate    = DateTime.Now;
                db.Entry(content).State = EntityState.Modified;
                db.SaveChanges();

                return(content.ID);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
        protected static void AddTenantToDatabaseWithSaveChanges(TenantBase newTenant, CompanyDbContext context)
        {
            if (newTenant == null)
            {
                throw new ArgumentNullException(nameof(newTenant));
            }

            if (!(newTenant is Company))
            {
                if (newTenant.Parent == null)
                {
                    throw new ApplicationException($"The parent cannot be null in type {newTenant.GetType().Name}.");
                }
                if (newTenant.Parent.ParentItemId == 0)
                {
                    throw new ApplicationException($"The parent {newTenant.Parent.Name} must be already in the database.");
                }
            }
            if (context.Entry(newTenant).State != EntityState.Detached)
            {
                throw new ApplicationException($"You can't use this method to add a tenant that is already in the database.");
            }

            //We have to do this request using a transaction to make sure the DataKey is set properly
            using (var transaction = context.Database.BeginTransaction())
            {
                //set up the backward link (if Parent isn't null)
                newTenant.Parent?._children.Add(newTenant);
                context.Add(newTenant);  //also need to add it in case its the company
                // Add this to get primary key set
                context.SaveChanges();

                //Now we can set the DataKey
                newTenant.SetDataKeyFromHierarchy();
                context.SaveChanges();

                transaction.Commit();
            }
        }
Пример #25
0
 public void Edit(Document b)
 {
     b.ModifiedDate         = DateTime.Now;
     context.Entry(b).State = EntityState.Modified;
     context.SaveChanges();
 }
Пример #26
0
 public void Edit(Company b)
 {
     context.Entry(b).State = EntityState.Modified;
     context.SaveChanges();
 }
Пример #27
0
        public static async Task <string> UploadToBlob(string connectionString, string blobContainer, string filename, Guid Id, string docType, Stream stream)
        {
            CloudBlobContainer cloudBlobContainer = null;
            CompanyDbContext   context            = new CompanyDbContext();//TODO: DI

            if (CloudStorageAccount.TryParse(connectionString, out CloudStorageAccount storageAccount))
            {
                try
                {
                    // Create the CloudBlobClient that represents the Blob storage endpoint for the storage account.
                    CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();

                    // Create a container called 'uploaddownloadblob' and append a GUID value to it to make the name unique.
                    cloudBlobContainer = cloudBlobClient.GetContainerReference(blobContainer);

                    await cloudBlobContainer.CreateIfNotExistsAsync();

                    // Get a reference to the blob address, then upload the file to the blob.
                    CloudBlockBlob cloudBlockBlob = cloudBlobContainer.GetBlockBlobReference(Id + "/" + filename);
                    if (stream != null)
                    {
                        cloudBlockBlob.UploadFromStreamAsync(stream, null, null, null).GetAwaiter().GetResult();
                        //Set metadata
                        //cloudBlockBlob.Metadata["DocType"] = docType;
                        //cloudBlockBlob.SetMetadataAsync().GetAwaiter().GetResult();
                    }
                    else
                    {
                        return("failed");
                    }

                    //SAS Token: Default for Editor.
                    SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy
                    {
                        //Access is Valid for a week
                        SharedAccessExpiryTime = DateTime.UtcNow.AddYears(1),
                        Permissions            = SharedAccessBlobPermissions.Read | SharedAccessBlobPermissions.Write
                    };

                    //Generate the shared access signature on the blob, setting the constraints directly on the signature.
                    string sasBlobToken = cloudBlockBlob.GetSharedAccessSignature(sasConstraints);

                    //Save File location in Document Table:
                    var c = (from r in context.Document where r.Id == Id select r).FirstOrDefault();
                    c.URI                  = cloudBlockBlob.Uri.AbsoluteUri;
                    c.SASToken             = sasBlobToken;
                    c.Title                = filename;
                    context.Entry(c).State = EntityState.Modified;
                    context.SaveChanges();

                    return(cloudBlockBlob.Uri.AbsoluteUri + sasBlobToken);
                }
                catch (StorageException ex)
                {
                    return("failed");
                }
                finally
                {
                    // OPTIONAL: Clean up resources, e.g. blob container
                    //if (cloudBlobContainer != null)
                    //{
                    //    await cloudBlobContainer.DeleteIfExistsAsync();
                    //}
                }
            }
            else
            {
                return("failed");
            }
        }