Пример #1
0
 public async Task Delete(int id) => await Task.Run(() =>
 {
     TEntity entityToDelete = GetById(id).Result;
     _context.Set <TEntity>().Attach(entityToDelete);
     _context.Entry(entityToDelete).State = EntityState.Deleted;
     return(_context.Set <TEntity>().Remove(entityToDelete));
 });
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            if (id != category.categoryId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #3
0
        public ActionResult Edit([Bind(Include = "TicketID,Title,Body,Status,CreatedAt,AgentID")] Ticket ticket)
        {
            if (ModelState.IsValid)
            {
                db.Entry(ticket).State = EntityState.Modified;                              // DECLARE THAT THE ENTITY HAS BEEN CHANGED

                if (ticket.Status.Equals(Ticket.TicketStatus.Solved))                       // IF THE TICKET CHANGES STATUS
                {
                    int targetAgentId        = ticket.AgentID;                              // FIND AGENT ON THE TICKET
                    var targetAgent          = db.Agents.Find(targetAgentId).AgentID;       // FIND THAT AGENT IN DB
                    int ticketSolvedCount    = db.Agents.Find(targetAgent).TicketsSolved;   // GET # OF SOLVED TICKETS AGENT HAS
                    int newSolvedTicketCount = ticketSolvedCount + 1;                       // UPDATE THE NUMBER
                    db.Agents.Find(targetAgent).TicketsSolved = newSolvedTicketCount;       // SET THE NEW NUMBER

                    int ticketOpenedCount    = db.Agents.Find(targetAgent).TicketsAssigned; // FIND # OF ASSIGNED TICKETS
                    int newticketOpenedCount = ticketOpenedCount - 1;                       // UPDATE THE NUMBER
                    db.Agents.Find(targetAgent).TicketsAssigned = newticketOpenedCount;     // SET THE NEW NUMBER
                }
                ticket.CreatedAt = DateTime.Now;                                            // SET NEW TIME
                db.SaveChanges();                                                           // SAVE CHANGES
                return(RedirectToAction("Index"));
            }
            ViewBag.AgentID = new SelectList(db.Agents, "AgentId", "FirstName", ticket.AgentID); // GET AGENT LIST
            return(View(ticket));
        }
Пример #4
0
        public IHttpActionResult PutEmployee(int id, Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employee.EmployeeId)
            {
                return(BadRequest());
            }

            db.Entry(employee).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EmployeeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #5
0
        public bool Edit(Ticket ticket)
        {
            // Qui bisogna usare una modalità disconnessa
            using var ctx = new TicketContext();
            bool saved = false;

            do
            {
                try
                {
                    if (ticket == null)
                    {
                        return(false);
                    }

                    // Se volessi fermare il programma per andare a simulare la concurrency modificando i dati da sql
                    // le due righe seguenti servono per far fermare l'applicazione e lasciare il tempo di modificare i dati
                    //Console.WriteLine("Wait");
                    //Console.ReadLine();

                    ctx.Entry <Ticket>(ticket).State = EntityState.Modified;
                    ctx.SaveChanges();

                    saved = true;
                }
                catch (DbUpdateConcurrencyException exc)
                {
                    Console.WriteLine("Error: " + exc.Message);
                    saved = false;
                }
            } while (!saved);

            return(true);
        }
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.userId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public bool Update(Ticket item)
        {
            using (var _ctx = new TicketContext())
            {
                bool saved = false;
                do
                {
                    try
                    {
                        _ctx.Entry <Ticket>(item).State = EntityState.Modified;
                        _ctx.SaveChanges();

                        saved = true;
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        foreach (var entity in ex.Entries)
                        {
                            var dbValues = entity.GetDatabaseValues();
                            entity.OriginalValues.SetValues(dbValues);
                        }
                    }
                } while (!saved);

                return(true);
            }
        }
Пример #8
0
        public async Task <IActionResult> PutTicket(long id, Ticket ticket)
        {
            if (id != ticket.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public bool Edit(Ticket ticket)
        {
            using var ctx = new TicketContext();
            bool saved = false;

            do
            {
                try
                {
                    if (ticket == null)
                    {
                        return(false);
                    }

                    Console.WriteLine("Smandrappa il Ticket e poi premi enter ...");
                    Console.ReadKey();

                    ctx.Entry <Ticket>(ticket).State = EntityState.Modified;
                    ctx.SaveChanges();

                    saved = true;
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    // ...
                    Console.WriteLine("Error: " + ex.Message);
                    //return false;
                    saved = false;
                }
            } while (!saved);

            return(true);
        }
Пример #10
0
        public IHttpActionResult PutTicket(int id, Ticket ticket)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != ticket.TicketId)
            {
                return(BadRequest());
            }

            db.Entry(ticket).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TicketExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #11
0
 private void routeTicketToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (TicketContext db = new TicketContext())
     {
         var p = db.Tickets.FirstOrDefault();
         db.Entry(p).Reference("Airplane").Load();
         Console.WriteLine($"{p.Price} - {p.Airplane.Airplane_class}");
     }
 }
Пример #12
0
 public ActionResult Edit([Bind(Include = "DepartmentId,DepartmentName")] Department department)
 {
     if (ModelState.IsValid)
     {
         db.Entry(department).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(department));
 }
Пример #13
0
 public ActionResult Edit([Bind(Include = "ID,Title,Description,Date,Email,Status,CustomerResponse,EmployeeResponse,ScheduledTime,ScheduledDay")] Ticket ticket)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ticket).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ticket));
 }
 public ActionResult Edit([Bind(Include = "PassengerID,FirstName,LastName,TravelDate")] Passenger passenger)
 {
     if (ModelState.IsValid)
     {
         db.Entry(passenger).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(passenger));
 }
Пример #15
0
 public ActionResult Edit([Bind(Include = "ID,Title,Description,DateCreated,Status")] Ticket ticket)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ticket).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ticket));
 }
Пример #16
0
        public TicketDTO EditTicket(TicketDTO ticketDTO)
        {
            TicketMapper ticketMapper = new TicketMapper();
            Ticket       ticket       = ticketMapper.TicketDTOToTicket(ticketDTO);

            _context.Entry(ticket).State = EntityState.Modified;
            _context.SaveChanges();
            ticketDTO = ticketMapper.TicketoToTicketDTO(ticket);
            return(ticketDTO);
        }
Пример #17
0
 public ActionResult Edit([Bind(Include = "TicketID,TicketName,Destination")] Ticket ticket)
 {
     if (ModelState.IsValid)
     {
         db.Entry(ticket).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(ticket));
 }
Пример #18
0
 public ActionResult Edit([Bind(Include = "KeywordID,Keyword,DepartmentID")] KeywordsDepartment keywordsDepartment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(keywordsDepartment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentId", "DepartmentName", keywordsDepartment.DepartmentID);
     return(View(keywordsDepartment));
 }
Пример #19
0
        public async Task <IActionResult> PutTicketItem(long id, TicketItem item)
        {
            if (id != item.Id)
            {
                return(BadRequest());
            }

            _context.Entry(item).State = EntityState.Modified;
            await _context.SaveChangesAsync();

            return(NoContent());
        }
 public ActionResult Edit([Bind(Include = "BookingID,PassengerID,TicketID")] Booking booking)
 {
     if (ModelState.IsValid)
     {
         db.Entry(booking).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PassengerID = new SelectList(db.Passengers, "PassengerID", "FirstName", booking.PassengerID);
     ViewBag.TicketID    = new SelectList(db.Tickets, "TicketID", "TicketName", booking.TicketID);
     return(View(booking));
 }
Пример #21
0
        /// <summary>
        /// Update a user.
        /// </summary>
        /// <param name="user">The user with changed values</param>
        public async Task <Domain.Models.Users> UpdateUserAsync(int id, Domain.Models.Users user)
        {
            _logger.LogInformation("Updating user with ID {userId}", id);

            DataAccess.Entities.Users currentEntity = await _dbContext.Users.FindAsync(id);

            var newEntity = Mapper.MapUsers(user);

            newEntity.Id = id;
            _dbContext.Entry(currentEntity).CurrentValues.SetValues(newEntity);
            return(user);
        }
Пример #22
0
        public async Task <string> Post([FromBody] Booking booking)
        {
            var ticketItem = await _context.TicketItems.FindAsync(booking.TicketId);

            if (ticketItem == null)
            {
                return("there is no ticket id " + booking.TicketId);
            }
            if (!ticketItem.State.Equals("available"))
            {
                return("ticket " + booking.TicketId + " is not avaliable");
            }
            UserMessage message = new UserMessage
            {
                Id    = booking.UserId,
                State = 0
            };
            await _bus.PublishAsync(message);

            int res = UserMessageConsumer.getRes();

            if (res == 1)
            {
                System.Console.WriteLine("user {0} exits", booking.UserId);
                //存在,发送消息给payment,锁定票
                UserTicketMessage userTicketMessage = new UserTicketMessage
                {
                    UserId   = booking.UserId,
                    TicketId = booking.TicketId
                };
                await _bus.PublishAsync(userTicketMessage);

                ticketItem.State = "locked";
                _context.Entry(ticketItem).State = EntityState.Modified;
                await _context.SaveChangesAsync();

                int    paymentId = TicketMessageConsumer.getPaymentId();
                string mess      = "user " + booking.UserId + " locked ticket " + booking.TicketId + " and payment id is " + paymentId;
                return(mess);
            }
            else
            {
                System.Console.WriteLine("user {0} does not exist", booking.UserId);
                string mess = "user " + booking.UserId + " does not exist";
                return(mess);
            }
        }
        public Person Update(Person person)
        {
            var personcheck = FindById((int)person.Id);

            if (personcheck == null)
            {
                return(new Person());
            }

            try
            {
                _ticketContext.Entry(personcheck).CurrentValues.SetValues(person);
                _ticketContext.SaveChanges();
                return(personcheck);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #24
0
        internal bool Edit(Ticket t)
        {
            using var ctx = new TicketContext();
            try
            {
                if (t == null)
                {
                    return(false);
                }

                ctx.Entry <Ticket>(t).State = EntityState.Modified;
                ctx.SaveChanges();
                return(true);
            }
            catch (DbUpdateConcurrencyException ex)
            {
                Console.WriteLine(("Error: " + ex.Message));
                return(false);
            }
        }
Пример #25
0
        public T Update(T obj)
        {
            var check = FindById(obj.Id);

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

            try
            {
                _ticketContext.Entry(check).CurrentValues.SetValues(obj);
                _ticketContext.SaveChanges();
                return(check);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #26
0
        public ActionResult Edit([Bind(Include = "AgentID,Surname,FirstName,Email,DepartmentID")] Agent agent)
        {
            if (ModelState.IsValid)
            {
                db.Entry(agent).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.DepartmentID = new SelectList(db.Departments, "DepartmentID", "DepartmentName", agent.DepartmentID);

            var uid = ViewBag.UserId = new SelectList(dbc.Users, "Id", "UserName", agent.UserId); // FETCH USER ID
            var ur  = new SelectList(dbc.Roles, "Id", "Name", agent.Role);                        // FETCH ROLES

            ViewBag.Role = ur;

            var userStore   = new UserStore <ApplicationUser>(dbc);
            var userManager = new UserManager <ApplicationUser>(userStore);

            userManager.AddToRole(agent.UserId, agent.Role);


            return(View(agent));
        }
Пример #27
0
 public void UpdateCategory(TicketCategory ticketCategory)
 {
     _ticketContext.Entry(ticketCategory).State = EntityState.Modified;
     _ticketContext.SaveChanges();
 }
 public void UpdateTicket(Ticket ticket)
 {
     _ticketContext.Entry(ticket).State = EntityState.Modified;
     _ticketContext.SaveChanges();
 }