public override bool AddProduct(string title_, decimal price, string comment_)
        {
            ProductDTO product = new ProductDTO();

            product.UserId = currentUser.Id;

            product.ProductName = title_;
            product.Price       = price;

            ResponceDTO comment = new ResponceDTO();

            comment.Responce = comment_;

            responseDal.Add(comment);

            var comms = responseDal.Find(comment.Responce);

            product.ResponceId = comms[0].Id;
            productDal.Add(product);
            return(true);
        }
Example #2
0
        public List <ResponceDTO> GetAll()
        {
            using (SqlConnection conn = new SqlConnection(this.connectionString))
                using (SqlCommand comm = conn.CreateCommand())
                {
                    conn.Open();
                    comm.CommandText = "select * from Responces";
                    SqlDataReader reader = comm.ExecuteReader();

                    List <ResponceDTO> responces = new List <ResponceDTO>();
                    while (reader.Read())
                    {
                        ResponceDTO responce = new ResponceDTO();

                        responce.Id       = (long)reader["Id"];
                        responce.Responce = reader["Responce"].ToString();
                        responces.Add(responce);
                    }

                    return(responces);
                }
        }
Example #3
0
        public List <ResponceDTO> Find(string reponce)
        {
            using (SqlConnection conn = new SqlConnection(this.connectionString))
                using (SqlCommand comm = conn.CreateCommand())
                {
                    conn.Open();
                    comm.CommandText = "select * from Responces where ResponceName Like '%" + reponce + "%'";
                    SqlDataReader reader = comm.ExecuteReader();

                    List <ResponceDTO> responces = new List <ResponceDTO>();
                    while (reader.Read())
                    {
                        ResponceDTO responce = new ResponceDTO();

                        responce.Id       = (long)reader["Id"];
                        responce.Responce = reader["Responce"].ToString();
                        responces.Add(responce);
                    }
                    conn.Close();
                    return(responces);
                }
        }
Example #4
0
        public ResponceDTO Add(ResponceDTO responce)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(this.connectionString))
                    using (SqlCommand comm = conn.CreateCommand())
                    {
                        conn.Open();
                        string query = "";
                        query = "Insert into Responces(Responce) " +
                                $"values('{responce.Responce}')";

                        Console.WriteLine(query);
                        comm.CommandText = query;
                        comm.ExecuteNonQuery();
                        conn.Close();
                    }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return(responce);
        }
Example #5
0
        public async Task <ActionResult> SaveExecutorResponce(UserActivityViewModel activityModel, string indentPrice)
        {
            var clientId = Session["Id"];

            if (clientId == null)
            {
                return(RedirectToAction("Registration", "Executor"));
            }

            int    executorId   = Convert.ToInt32(clientId);
            string executorName = Session["Name"].ToString();

            double?priceOfIndent;

            Regex patternForPrice = new Regex(@"^[0-9]*\,?[0-9]+\s?$", RegexOptions.IgnoreCase);

            if (indentPrice == null)
            {
                priceOfIndent = null;
            }
            else if (patternForPrice.IsMatch(indentPrice.Trim()))
            {
                try
                {
                    priceOfIndent = Convert.ToDouble(indentPrice.Trim());
                }
                catch (Exception e)
                {
                    TempData["ErrorMessage"] = "Были введены некорректные данные, попробуйте снова!";

                    return(RedirectToAction("ShowIndent", "Indent", new { id = activityModel.IndentId }));
                }
            }
            else
            {
                TempData["ErrorMessage"] = "Были введены некорректные данные, попробуйте снова!";

                return(RedirectToAction("ShowIndent", "Indent", new { id = activityModel.IndentId }));
            }

            ResponceDTO responceDTO = new ResponceDTO()
            {
                Price    = priceOfIndent,
                IndentId = activityModel.IndentId,
                Executor = new ExecutorDTO()
                {
                    ExecutorId = executorId
                },
                ResponceText = activityModel.Comment
            };

            await _userActivityService.SaveResponce(responceDTO);

            string    cacheKey     = "show-indent-" + activityModel.IndentId.ToString();
            IndentDTO cachedIndent = HttpContext.Cache[cacheKey] as IndentDTO;

            if (cachedIndent != null)
            {
                HttpContext.Cache.Remove(cacheKey);
            }

            NotificationDTO notificationDTO = GenerateNotification(activityModel, Role.Customer, "Responce");

            notificationDTO.FromId   = executorId;
            notificationDTO.FromName = executorName;

            await _userActivityService.SaveNotification(notificationDTO);

            return(RedirectToAction("ShowIndent", "Indent", new { id = activityModel.IndentId }));
        }
        public async Task SaveResponce(ResponceDTO responceDTO)
        {
            Responce responce = _mapper.Map <Responce>(responceDTO);

            await _database.Responces.Create(responce);
        }