Beispiel #1
0
        public ActionResult UpdateFhoto(ImageViewModel imageViewModel)
        {
            int UsId = Convert.ToInt32(Session["Humanid"]);

            if (UsId == 0)
            {
                return(RedirectToAction("LogON", "Enter"));
            }
            else
            {
                var    File = imageViewModel.Photo;
                Chater s    = db.chaters.Find(UsId);
                if (File != null)
                {
                    var    fileExtention = System.IO.Path.GetExtension(File.FileName);
                    string id_extention  = UsId + fileExtention;
                    string ImgPath       = "~/ProfilePhotos/" + id_extention;
                    s.ImageLink       = ImgPath;
                    db.Entry(s).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    var path = Server.MapPath("~/ProfilePhotos/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    if ((System.IO.File.Exists(path + id_extention)))
                    {
                        System.IO.File.Delete(path + id_extention);
                    }
                    File.SaveAs((path + id_extention));
                }
                return(RedirectToAction("EditProfile", "Enter"));
            }
        }
Beispiel #2
0
        public ActionResult RegistChater(ChaterViewModel chaterViewModel)
        {
            bool ChaterNameExists = db.chaters.Any(x => x.ChaterkName == chaterViewModel.ChaterkName);

            if (ChaterNameExists)
            {
                ViewBag.NameAlert = "Это имя уже кем то используется";
                return(View());
            }
            bool MailExists = db.chaters.Any(x => x.Email == chaterViewModel.Email);

            if (MailExists)
            {
                ViewBag.MailAlert = "Эта почта уже используется";
                return(View());
            }
            Chater chater = new Chater();

            chater.ChaterkName    = chaterViewModel.ChaterkName;
            chater.Email          = chaterViewModel.Email;
            chater.Pass           = chaterViewModel.Pass;
            chater.ImageLink      = "";
            chater.DateRegistered = DateTime.Now;
            db.chaters.Add(chater);
            db.SaveChanges();
            return(RedirectToAction("LogON", "Enter"));
        }
Beispiel #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,User,Message")] Chater chater)
        {
            if (id != chater.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(chater);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ChaterExists(chater.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(chater));
        }
        public async Task <ActionResult <Chater> > PostChater(Chater chater)
        {
            _context.Chater.Add(chater);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetChater", new { id = chater.Id }, chater));
        }
        public async Task <IActionResult> PutChater(int id, Chater chater)
        {
            if (id != chater.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Beispiel #6
0
        public async Task <IActionResult> Create([Bind("Id,User,Message")] Chater chater)
        {
            if (ModelState.IsValid)
            {
                _context.Add(chater);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(chater));
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello gRpcChat!");
            Console.Write("Name:");
            string name = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(name))
            {
                name = Guid.NewGuid().ToString();
            }

            Console.WriteLine();

            Console.WriteLine("Hello " + name);

            string message = null;

            Chater chater = new Chater(name);

            chater.Login();

            do
            {
                message = Console.ReadLine();

                if (string.IsNullOrWhiteSpace(message))
                {
                    continue;
                }

                chater.Send(message);
            } while (message != "q");

            Console.WriteLine($"{name} exit");
            Console.ReadLine();
        }