コード例 #1
0
        public async Task <IActionResult> PutTenantProfile(string LogId, Maintenance maintenance)
        {
            if (LogId != maintenance.LogId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
コード例 #2
0
        public async Task <ActionResult <Maintenance> > UpdateUnit(int id, Maintenance maintenance)
        {
            try
            {
                Maintenance unit = await _context.Maintenance.FindAsync(id);;

                if (unit != null)
                {
                    // So you don't have to write date and time with Postman.
                    maintenance.Updated = DateTime.Now;

                    // Prevents crashing of the server, cause we don't set id when casting maintenance parameter.
                    maintenance.Id = unit.Id;

                    _context.Entry(unit).CurrentValues.SetValues(maintenance);
                    await _context.SaveChangesAsync();

                    return(Content($"{unit.Updated} Unit an ID {maintenance.Id} updated!\nNew data: {unit.Unit}\n{unit.Desc}\n{unit.Importance}\n{unit.State}"));
                }

                return(Content("Unit with an ID {id} not found!"));
            }
            catch (ArgumentNullException e)
            {
                return(Content(e.Message));
            }
            catch (DbUpdateException e)
            {
                return(Content($"Please take a look at your data and refer to the docs for proper names and types.\n{e.InnerException.Message}."));
            }
        }
コード例 #3
0
 public void Update(Reservation reservation)
 {
     using (var context = new MaintenanceContext())
     {
         context.Entry(reservation).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #4
0
 public void Update(Maintenance maintenance)
 {
     using (var context = new MaintenanceContext())
     {
         context.Entry(maintenance).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
コード例 #5
0
        /// <summary>
        /// Returns a single object with a primary key of the provided id
        /// </summary>
        /// <remarks>Synchronous</remarks>
        /// <param name="id">The primary key of the object to fetch</param>
        /// <returns>A single object with the provided primary key or null</returns>
        public TEntity Get(int id, bool option = false)
        {
            var entity = this.Entities.Find(id);

            if (!option)
            {
                Context.Entry(entity).State = EntityState.Detached;
            }
            return(entity);
        }
コード例 #6
0
 public Machine Update(Machine obj)
 {
     db.Entry(obj).State = EntityState.Modified;
     db.SaveChanges();
     return(obj);
 }
コード例 #7
0
 public Schedule Reload(Schedule obj)
 {
     db.Entry(obj).Reference(p => p.Machine).Load();
     db.Entry(obj).Reference(p => p.Employee).Load();
     return(obj);
 }
コード例 #8
0
 public Employee Update(Employee obj)
 {
     db.Entry(obj).State = EntityState.Modified;
     db.SaveChanges();
     return(obj);
 }