public async Task <IActionResult> Edit(int id, [Bind("Id,ActivityId,RatingDate,RatingTypeId,Score")] ClientRating clientRating)
        {
            if (id != clientRating.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(clientRating);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientRatingExists(clientRating.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(clientRating));
        }
        public IList <ClientRating> Get()
        {
            try
            {
                Logger.LogInfo("Get: ClientRating process start");
                IList <ClientRating> lstClientRating = new List <ClientRating>();

                DataTable dtAppConfig = DataBase.DBService.ExecuteCommand(string.Format(SELECT_ALL));
                foreach (DataRow dr in dtAppConfig.Rows)
                {
                    ClientRating ClientRating = convertToClientRatingObject(dr);
                    lstClientRating.Add(ClientRating);
                }
                Logger.LogInfo("Get: ClientRating process completed.");
                return(lstClientRating);
            }
            catch (Exception ex)
            {
                StackTrace st = new StackTrace();
                StackFrame sf = st.GetFrame(0);
                MethodBase currentMethodName = sf.GetMethod();
                LogDebug(currentMethodName.Name, ex);
                return(null);
            }
        }
        private ClientRating convertToClientRatingObject(DataRow dr)
        {
            ClientRating ClientRating = new ClientRating();

            ClientRating.Rating = dr.Field <string>("Rating");
            return(ClientRating);
        }
        public async Task <IActionResult> Create([Bind("Id,ActivityId,RatingDate,RatingTypeId,Score")] ClientRating clientRating)
        {
            if (ModelState.IsValid)
            {
                _context.Add(clientRating);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(clientRating));
        }
        public Result Delete(ClientRating ClientRating)
        {
            var result = new Result();

            try
            {
                ClientRatingService ClientRatingService = new ClientRatingService();
                ClientRatingService.Delete(ClientRating);
                result.IsSuccess = true;
            }
            catch (Exception exception)
            {
                result.IsSuccess     = false;
                result.ExceptionInfo = exception;
            }
            return(result);
        }
 public void Delete(ClientRating ClientRating)
 {
     try
     {
         DataBase.DBService.ExecuteCommand(string.Format(DELETE_BY_ID, ClientRating.Rating));
         Activity.ActivitiesService.Add(ActivityType.DeleteClientRating, EntryStatus.Success,
                                        Source.Server, ClientRating.UpdatedByUserName, ClientRating.Rating, ClientRating.MachineName);
     }
     catch (Exception ex)
     {
         StackTrace st = new StackTrace();
         StackFrame sf = st.GetFrame(0);
         MethodBase currentMethodName = sf.GetMethod();
         LogDebug(currentMethodName.Name, ex);
         throw ex;
     }
 }
Beispiel #7
0
        public static ClientRating UpdateRating(ClientRating clientRating)
        {
            try
            {
                var endPointString = endPointQLBH + "api/ratings";
                var ratingUpdate   = Task.Run(() => PutAsync <ClientRating>(endPointString, clientRating)).Result;

                return(ratingUpdate);
            }
            catch (BusinessLayerException)
            {
                throw new BusinessLayerException(500, "#1001002 Không cập nhật được dữ liệu đánh giá.");
            }
            catch (Exception)
            {
                throw new BusinessLayerException(500, "#1001003 Không cập nhật được dữ liệu đánh giá.");
            }
        }
        public void Add(ClientRating ClientRating)
        {
            try
            {
                string clientName = DataBase.DBService.ExecuteCommandScalar(string.Format(GET_CLIENT_NAME_QUERY, 0));

                DataBase.DBService.ExecuteCommand(string.Format(INSERT_QUERY,
                                                                ClientRating.Rating,
                                                                ClientRating.CreatedOn.ToString("yyyy-MM-dd hh:mm:ss"), ClientRating.CreatedBy,
                                                                ClientRating.UpdatedOn.ToString("yyyy-MM-dd hh:mm:ss"), ClientRating.UpdatedBy));

                Activity.ActivitiesService.Add(ActivityType.CreateClientRating, EntryStatus.Success,
                                               Source.Server, ClientRating.UpdatedByUserName, ClientRating.Rating, ClientRating.MachineName);
            }
            catch (Exception ex)
            {
                StackTrace st = new StackTrace();
                StackFrame sf = st.GetFrame(0);
                MethodBase currentMethodName = sf.GetMethod();
                LogDebug(currentMethodName.Name, ex);
                throw ex;
            }
        }
        public ActionResult RateProductIndex(int?proId, int?rateId, int?rate)
        {
            var p = CSDLQLBH.GetRatingsByProduct(proId).FirstOrDefault();

            if (p != null)
            {
                switch (rateId)
                {
                case 1:
                    if (rate == 1)
                    {
                        p.One += 1;
                    }
                    else
                    {
                        p.One -= 1;
                    }
                    break;

                case 2:
                    if (rate == 1)
                    {
                        p.Two += 1;
                    }
                    else
                    {
                        p.Two -= 1;
                    }
                    break;

                case 3:
                    if (rate == 1)
                    {
                        p.Three += 1;
                    }
                    else
                    {
                        p.Three -= 1;
                    }
                    break;

                case 4:
                    if (rate == 1)
                    {
                        p.Four += 1;
                    }
                    else
                    {
                        p.Four -= 1;
                    }
                    break;

                case 5:
                    if (rate == 1)
                    {
                        p.Five += 1;
                    }
                    else
                    {
                        p.Five -= 1;
                    }
                    break;
                }
                p.Rate = ((p.One * 1) + (p.Two * 2) + (p.Three * 3) + (p.Four * 4) + (p.Five * 5)) / (p.One + p.Two + p.Three + p.Four + p.Five);

                CSDLQLBH.UpdateRating(p);
            }
            else
            {
                ClientRating ra = new ClientRating
                {
                    ProID = proId,
                    One   = 0,
                    Two   = 0,
                    Three = 0,
                    Four  = 0,
                    Five  = 0
                };
                switch (rateId)
                {
                case 1:
                    ra.One = rate;
                    break;

                case 2:
                    ra.Two = rate;
                    break;

                case 3:
                    ra.Three = rate;
                    break;

                case 4:
                    ra.Four = rate;
                    break;

                case 5:
                    ra.Five = rate;
                    break;
                }
                ra.Rate = ((ra.One * 1) + (ra.Two * 2) + (ra.Three * 3) + (ra.Four * 4) + (ra.Five * 5)) / (ra.One + ra.Two + ra.Three + ra.Four + ra.Five);

                CSDLQLBH.InsertRating(ra);
            }
            return(RedirectToAction("Index", "Home"));
        }