Пример #1
0
 public virtual void Delete(TEntity entityToDelete)
 {
     if (context.Entry(entityToDelete).State == EntityState.Detached)
     {
         dbSet.Attach(entityToDelete);
     }
     dbSet.Remove(entityToDelete);
 }
Пример #2
0
        public static bool ChangeNameAndEmail(int userid, string NewUsername, string NewUseremail)
        {
            bool result;

            try
            {
                using (var userDb = new DataAccessContext())
                {
                    var userRecord = userDb.users.Find(userid);
                    if (userRecord != null)
                    {
                        if (userRecord.email != NewUseremail)
                        {
                            CreateEmailChangeLog(userRecord.email, NewUseremail);
                        }
                        userRecord.name  = NewUsername;
                        userRecord.email = NewUseremail;
                        userDb.Entry(userRecord).State = System.Data.Entity.EntityState.Modified;
                        userDb.SaveChanges();
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            catch (Exception)
            {
                //TODO: Log exception to log
                result = false;
            }
            return(result);
        }
Пример #3
0
        public static bool ChangePassword(int userid, string NewPassword)
        {
            bool result;

            try
            {
                using (var userDb = new DataAccessContext())
                {
                    var userRecord = userDb.users.Find(userid);
                    if (userRecord != null)
                    {
                        userRecord.password            = NewPassword.CalculateMd5Hash();
                        userDb.Entry(userRecord).State = System.Data.Entity.EntityState.Modified;
                        userDb.SaveChanges();
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            catch (Exception)
            {
                //TODO: Log exception to log
                result = false;
            }

            return(result);
        }
Пример #4
0
        public HttpResponseMessage UpdateDeparment(EmployeeViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    DepartmentModel emp = new DepartmentModel();
                    emp.DepartmentID   = model.DepartmentID;
                    emp.DepartmentName = model.DepartmentName;


                    context.Entry(emp).State = System.Data.Entity.EntityState.Modified;
                    var result = context.SaveChanges();
                    if (result > 0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, "Updated Successfully"));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Something wrong !"));
                    }
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something wrong !"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something wrong !", ex));
            }
        }
Пример #5
0
        public async Task <IActionResult> PutEmployee(int id, Employee employee)
        {
            if (id != employee.EmployeeID)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Пример #6
0
        public static bool ChangeGame(int gameid, string NewName, string NewDescription)
        {
            bool result;

            try
            {
                using (var GameDb = new DataAccessContext())
                {
                    var gameRecord = GameDb.game_systems.Find(gameid);
                    if (gameRecord != null)
                    {
                        gameRecord.name                = NewName;
                        gameRecord.description         = NewDescription;
                        GameDb.Entry(gameRecord).State = System.Data.Entity.EntityState.Modified;
                        GameDb.SaveChanges();
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            catch
            {
                //TODO: Log exception to log
                result = false;
            }

            return(result);
        }
Пример #7
0
        public IHttpActionResult PutUser(int id, User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.Id)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #8
0
        public HttpResponseMessage UpdateEmployee(EmployeeViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    EmployeeModel emp = new EmployeeModel();
                    emp.EmployeeID = model.EmployeeID;
                    emp.FirstName  = model.FirstName;
                    emp.LastName   = model.LastName;
                    emp.Address    = model.Address;
                    emp.Salary     = model.Salary;
                    emp.DOB        = Convert.ToDateTime(model.DOB.ToString("yyyy-MM-dd HH:mm:ss.fff"));

                    context.Entry(emp).State = System.Data.Entity.EntityState.Modified;
                    var result = context.SaveChanges();
                    if (result > 0)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, "Updated Successfully"));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Something wrong !"));
                    }
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something wrong !"));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something wrong !", ex));
            }
        }
Пример #9
0
 public ActionResult Edit([Bind(Include = "InstitutionId,InstitutionName,CreateDate")] Institution institution)
 {
     if (ModelState.IsValid)
     {
         db.Entry(institution).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(institution));
 }
Пример #10
0
 public ActionResult Edit([Bind(Include = "ID,Name,Gender,IdNum,School,TrainingDate,InstitutionId,InputDate")] Student student)
 {
     if (ModelState.IsValid)
     {
         db.Entry(student).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.InstitutionId = new SelectList(db.Institutions, "InstitutionId", "InstitutionName", student.InstitutionId);
     return(View(student));
 }
 public override async Task Update(ProductoModel producto)
 {
     try
     {
         _context.Entry(producto).State = EntityState.Modified;
         await _context.SaveChangesAsync();
     }
     catch (System.Exception)
     {
         throw;
     }
 }
Пример #12
0
        public TEntity UpdateExisting(TEntity entity)
        {
            Entities.Attach(entity);
            var dbEntityEntry = Context.Entry(entity);

            if (dbEntityEntry != null)
            {
                dbEntityEntry.State = EntityState.Modified;
            }

            return(entity);
        }
        public ActionResult Classificar(PacoteViagem pacote)
        {
            if (ModelState.IsValid)
            {
                objContext.Entry(pacote).State = EntityState.Modified;
                objContext.SaveChanges();
                return(RedirectToAction("Index"));
            }

            var pacotesViagens = objContext.PacoteViagens.ToList();

            return(View(pacotesViagens));
        }
Пример #14
0
        public static void ChangeMatchState(int gameId, int matchId, int status)
        {
            using (var db = new DataAccessContext())
            {
                var acceptedMatch = db.pairings.FirstOrDefault(match => match.id == matchId);

                if (acceptedMatch != null)
                {
                    acceptedMatch.status1         = status;
                    db.Entry(acceptedMatch).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }
Пример #15
0
        public static bool ChangeAdminState(int userid, int adminid)
        {
            bool   result;
            string oldstate = "";
            string newstate = "";

            try
            {
                using (var userDb = new DataAccessContext())
                {
                    var userRecord = userDb.users.Find(userid);
                    if (userRecord != null)
                    {
                        oldstate                       = userRecord.isadmin.ToString();
                        userRecord.isadmin             = !userRecord.isadmin;
                        userDb.Entry(userRecord).State = System.Data.Entity.EntityState.Modified;
                        userDb.SaveChanges();
                        newstate = userRecord.isadmin.ToString();
                        result   = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            catch (Exception)
            {
                //TODO: Log exception to log
                result = false;
            }
            finally
            {
                using (var LogDb = new DataAccessContext())
                {
                    var logentry = new log_admin();
                    logentry.timestamp     = DateTime.Now;
                    logentry.uid_affected  = userid;
                    logentry.uid_performed = adminid;
                    logentry.changed_from  = oldstate;
                    logentry.changed_to    = newstate;

                    LogDb.log_admin.Add(logentry);
                    LogDb.SaveChanges();
                }
            }

            return(result);
        }
Пример #16
0
        public bool Update(EmployeeViewModel item)
        {
            EmployeeModel emp = new EmployeeModel();

            emp.EmployeeID = item.EmployeeID;
            emp.FirstName  = item.FirstName;
            emp.LastName   = item.LastName;
            emp.Address    = item.Address;
            emp.Salary     = item.Salary;
            emp.DOB        = Convert.ToDateTime(item.DOB.ToString("yyyy-MM-dd HH:mm:ss.fff"));

            context.Entry(emp).State = System.Data.Entity.EntityState.Modified;
            var result = context.SaveChanges();

            return(result > 0 ? true : false);
        }
        public ActionResult Put(int id, [FromForm] string Name, int Age, string Gender, string Phone, string Email)
        {
            var target = dbContext.Customer.SingleOrDefault(c => c.ID == id);

            if (target != null && ModelState.IsValid)
            {
                var changedCus = new Customer();
                changedCus.ID     = target.ID;
                changedCus.Name   = Name;
                changedCus.Age    = Age;
                changedCus.Gender = Gender;
                changedCus.Phone  = Phone;
                changedCus.Email  = Email;
                dbContext.Entry(target).CurrentValues.SetValues(changedCus);
                dbContext.SaveChanges();
                return(Ok());
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #18
0
        public static bool ResetPassword(int uid)
        {
            bool result;

            try
            {
                using (var userDb = new DataAccessContext())
                {
                    var userRecord = userDb.users.Find(uid);
                    if (userRecord != null)
                    {
                        var newPassword = GetRandomPassword(32);
                        //email senden
                        result = EmailUtil.SendPasswordEmail(userRecord.email, newPassword);
                        if (result)
                        {
                            //nur wenn die email gesendet werden konnte, neues PW in DB schreiben
                            userRecord.password = newPassword.CalculateMd5Hash();
                            //notwendig???
                            userDb.Entry(userRecord).State = System.Data.Entity.EntityState.Modified;
                            userDb.SaveChanges();
                        }
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            catch (Exception)
            {
                //TODO: Log exception to log
                result = false;
            }

            return(result);
        }
Пример #19
0
 public virtual async Task Update(T item)
 {
     _context.Entry(item).State = EntityState.Modified;
     await _context.SaveChangesAsync().ConfigureAwait(false);
 }