예제 #1
0
        public IHttpActionResult PutEmployeeRating(int id, EmployeeRating employeeRating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != employeeRating.EmployeeRatingsID)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #2
0
        public async Task RecalculateRatingsAndCountsAsync(Operation action, Review review, double reviewAverageRating)
        {
            var recalculateTasks = new List <Task>();

            // recalculate customer ratings and counts
            if (review.ConsumerRating.HasValue)
            {
                CustomerRating ??= new Ratings();
                recalculateTasks.Add(Task.Run(() => CustomerRating.RecalculateRatingValues(action, review.ConsumerRating.Value, review.Weight)));
            }
            // recalculate employee ratings and counts
            if (review.EmployeeRating.HasValue)
            {
                EmployeeRating ??= new Ratings();
                recalculateTasks.Add(Task.Run(() => EmployeeRating.RecalculateRatingValues(action, review.EmployeeRating.Value, review.Weight)));
            }
            // recalculate society ratings and counts
            if (review.SocietyRating.HasValue)
            {
                SocietyRating ??= new Ratings();
                recalculateTasks.Add(Task.Run(() => SocietyRating.RecalculateRatingValues(action, review.SocietyRating.Value, review.Weight)));
            }

            // recalculate average ratings and counts
            AverageRating ??= new Ratings();
            recalculateTasks.Add(Task.Run(() => AverageRating.RecalculateRatingValues(action, reviewAverageRating, review.Weight)));

            await Task.WhenAll(recalculateTasks).ConfigureAwait(false);
        }
예제 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            fillUserData();
            EmployeeRating employeerating = db.EmployeeRatings.Find(id);

            db.EmployeeRatings.Remove(employeerating);
            db.SaveChanges();
            return(RedirectToAction("EmployeeRating", new { Employeeid = employeerating.EmployeeId }));
        }
예제 #4
0
        public void CreateEmployeeRating(int employeeId, int rating)
        {
            var employeeRating = new EmployeeRating
            {
                EmployeeId = employeeId,
                Rating     = rating
            };

            _db.Add(employeeRating);
            SaveChanges();
        }
예제 #5
0
        public IHttpActionResult GetEmployeeRating(int id)
        {
            EmployeeRating employeeRating = db.EmployeeRatings.Find(id);

            if (employeeRating == null)
            {
                return(NotFound());
            }

            return(Ok(employeeRating));
        }
예제 #6
0
        public IHttpActionResult PostEmployeeRating(EmployeeRating employeeRating)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.EmployeeRatings.Add(employeeRating);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = employeeRating.EmployeeRatingsID }, employeeRating));
        }
예제 #7
0
        public IHttpActionResult DeleteEmployeeRating(int id)
        {
            EmployeeRating employeeRating = db.EmployeeRatings.Find(id);

            if (employeeRating == null)
            {
                return(NotFound());
            }

            db.EmployeeRatings.Remove(employeeRating);
            db.SaveChanges();

            return(Ok(employeeRating));
        }
예제 #8
0
        // GET: /EmployeeRating/Details/5
        public ActionResult Details(int?id)
        {
            fillUserData();
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeRating employeerating = db.EmployeeRatings.Find(id);

            if (employeerating == null)
            {
                return(HttpNotFound());
            }
            return(View(employeerating));
        }
예제 #9
0
 public ActionResult Edit([Bind(Include = "id,Year,Rating,Status")] EmployeeRating employeerating)
 {
     fillUserData();
     if (ModelState.IsValid)
     {
         EmployeeRating oldRating = db.EmployeeRatings.Find(employeerating.id);
         oldRating.Year   = employeerating.Year;
         oldRating.Rating = employeerating.Rating;
         oldRating.Status = employeerating.Status;
         oldRating.LastModificationDate = DateTime.Now;
         db.Entry(oldRating).State      = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("EmployeeRating", new { Employeeid = oldRating.EmployeeId }));
     }
     return(View(employeerating));
 }
예제 #10
0
        public ActionResult Create([Bind(Include = "id,Year,Rating,Status,EmployeeId")] EmployeeRating employeerating)
        {
            fillUserData();
            if (ModelState.IsValid)
            {
                employeerating.CreationDate         = DateTime.Now;
                employeerating.LastModificationDate = DateTime.Now;
                var map = new Dictionary <string, Double>();
                map.Add("A", 50000);
                map.Add("B", 40000);
                map.Add("C", 30000);
                map.Add("D", 20000);
                map.Add("E", 10000);
                map.Add("F", 5000);
                //Update employee Salary with the rating
                if (employeerating.Status.Equals("Confirmed"))
                {
                    Employees employee = db.Employees.Find(employeerating.EmployeeId);
                    employeerating.SalaryBeforeUpdate = employee.TotalSalary;
                    employee.TotalSalary         += map[employeerating.Rating];
                    employee.lastModificationDate = DateTime.Now;
                    db.Entry(employee).State      = EntityState.Modified;
                    db.SaveChanges();

                    employeerating.SalaryAfterUpdate = employee.TotalSalary;
                }
                else
                {
                    Employees employee = db.Employees.Find(employeerating.EmployeeId);
                    employeerating.SalaryBeforeUpdate = employee.TotalSalary;
                    employeerating.SalaryAfterUpdate  = employee.TotalSalary;
                }

                db.EmployeeRatings.Add(employeerating);
                db.SaveChanges();
                return(RedirectToAction("EmployeeRating", new { Employeeid = employeerating.EmployeeId }));
            }

            return(View(employeerating));
        }
예제 #11
0
 // Update
 public void UpdateEmployeeRating(EmployeeRating employeeRating)
 {
     _db.EmployeeRating.Update(employeeRating);
     SaveChanges();
 }
예제 #12
0
        // CRUD operation for Employee Rating

        // Create
        public void CreateEmployeeRating(EmployeeRating employeeRating)
        {
            _db.Add(employeeRating);
            SaveChanges();
        }