Esempio n. 1
0
        public ActionResult Create([Bind(Include = "TopicID,TopicName,TopicClousureDate,TopicFinalClousureDate,TopicPostDate")] Topic topic)
        {
            if (ModelState.IsValid)
            {
                db.Topics.Add(topic);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(topic));
        }
        public ActionResult Create([Bind(Include = "CommentId,Comment,CommentOn,CommentBy,MagazineID")] ArticlesComment articlesComment)
        {
            if (ModelState.IsValid)
            {
                db.ArticlesComments.Add(articlesComment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MagazineID = new SelectList(db.Magazines, "MagazineID", "MagazineName", articlesComment.MagazineID);
            return(View(articlesComment));
        }
Esempio n. 3
0
        public static void CreateMagazineShipping(UsersSubscription usersSubscription)
        {
            using (var context = new MagazineContext())
            {
                List <MagazineShipping> magazines = new List <MagazineShipping>();

                foreach (Magazine magazine in context.Magazines.ToList())
                {
                    MagazineShipping newMagazineShipping = new MagazineShipping()
                    {
                        UsersSubscription = usersSubscription,
                        Magazine          = magazine,
                        DeliverTime       = DateTime.Now,
                        IsDelivered       = true
                    };
                    magazines.Add(newMagazineShipping);
                }

                do
                {
                    Console.WriteLine("Если вы получили все журналы нажмите на 1");

                    string delivered = Console.ReadLine().Trim();

                    if (delivered == "1")
                    {
                        context.MagazineShippings.AddRange(magazines);
                        context.SaveChanges();
                        break;
                    }
                } while (true);
            }
        }
Esempio n. 4
0
        public static void RegistrationMenu()
        {
            Console.WriteLine("===========\n" +
                              "РЕГИСТРАЦИЯ\n" +
                              "===========");

            Person newPerson = new Person()
            {
                Name        = SetInformation.SetName(),
                Surname     = SetInformation.SetSurname(),
                Address     = SetInformation.SetAddress(),
                PhoneNumber = SetInformation.SetPhoneNumber()
            };

            User newUser = new User()
            {
                Login    = SetInformation.SetLogin(),
                Password = SetInformation.SetPassword(),
                Person   = newPerson
            };

            using (var context = new MagazineContext())
            {
                if (!context.People.Contains(newPerson))
                {
                    if (!context.Users.Contains(newUser))
                    {
                        context.Users.Add(newUser);
                        context.SaveChanges();

                        Console.WriteLine("Зарегистрированно");
                    }
                }
            }
        }
Esempio n. 5
0
 public string Buy(Purchase purchase)
 {
     purchase.Date = DateTime.Now;
     // добавляем информацию о покупке в базу данных
     db.Purchases.Add(purchase);
     // сохраняем в бд все изменения
     db.SaveChanges();
     Buy1();
     return(purchase.Person + ", thanks for purchase!");
 }
Esempio n. 6
0
        public ActionResult Create(Magazine magazine, string receiver)
        {
            if (ModelState.IsValid)
            {
                List <FileDetail> fileDetails = new List <FileDetail>();
                for (int i = 0; i < Request.Files.Count; i++)
                {
                    var file = Request.Files[i];

                    if (file != null && file.ContentLength > 0)
                    {
                        var        fileName   = Path.GetFileName(file.FileName);
                        FileDetail fileDetail = new FileDetail()
                        {
                            FileName  = fileName,
                            Extension = Path.GetExtension(fileName),
                            Id        = Guid.NewGuid()
                        };
                        fileDetails.Add(fileDetail);

                        var path = Path.Combine(Server.MapPath("~/App_Data/Upload/"), fileDetail.Id + fileDetail.Extension);
                        file.SaveAs(path);
                    }
                }
                ViewBag.TopicID      = new SelectList(db.Topics, "TopicID", "TopicName", magazine.TopicID);
                magazine.FileDetails = fileDetails;
                db.Magazines.Add(magazine);
                db.SaveChanges();


                string subject = "Your student has submitted their post submission for your Topic";
                string body    = "Hi Marketing Coordinator, " + "Your student has submitted their post submission for your Topic: " + magazine.TopicName + " Student's name: " + User.Identity.Name + " Submit Date: " + DateTime.Now;
                WebMail.Send(receiver, subject, body);

                return(RedirectToAction("Index"));
            }

            return(View(magazine));
        }
        public static void DeleteSubsription(User user)
        {
            using (var context = new MagazineContext())
            {
                var userSub = context.UsersSubscriptions.Where(userSubscription => userSubscription.User.Id == user.Id).SingleOrDefault();
                if (userSub != null)
                {
                    context.UsersSubscriptions.Remove(userSub);
                    context.SaveChanges();
                    return;
                }

                throw new ArgumentNullException("Нет такого пользователя с такой подпиской");
            }
        }
Esempio n. 8
0
        public static void CreateMagazine()
        {
            Magazine newMagazine = new Magazine()
            {
                Name        = SetInformation.SetName(),
                Theme       = SetInformation.SetTheme(),
                DateOfIssue = DateTime.Now
            };

            using (var context = new MagazineContext())
            {
                context.Magazines.Add(newMagazine);
                context.SaveChanges();
            }
        }
        public static UsersSubscription AddSubsription(User user, SubsritionsType subsritionsType)
        {
            using (var context = new MagazineContext())
            {
                UsersSubscription newUsersSubscription = new UsersSubscription()
                {
                    Subscription = context.Subscriptions.Where(sub => sub.SubscriptionsTimeInMonth == (int)subsritionsType).SingleOrDefault(),
                    User         = context.Users.Where(searchUser => searchUser.Id == user.Id).SingleOrDefault()
                };

                context.UsersSubscriptions.Add(newUsersSubscription);
                context.SaveChanges();

                return(newUsersSubscription);
            }
        }
Esempio n. 10
0
        public async Task DeleteTeacherAsync(string id)
        {
            try
            {
                magazineContext.Teacher.Remove(magazineContext.Teacher.SingleOrDefault(t => t.Id == id));
                magazineContext.SaveChanges();

                string msg = String.Format("Преподаватель был удален!");
                Response.StatusCode = StatusCodes.Status200OK;
                await Response.WriteAsync(JsonConvert.SerializeObject(new { success = msg },
                                                                      new JsonSerializerSettings {
                    Formatting = Formatting.Indented
                }));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("error", e.Message);
                await Response.BadRequestHelper(ModelState.Values);
            }
        }
Esempio n. 11
0
        public ActionResult Registr(Customer cust)
        {
            cust.idcustomer = Guid.NewGuid();
            db.customer.Add(cust);
            db.SaveChanges();

            var myResult = db.customer.Where(c => c.name == cust.name).Select(c => new { c.name, c.product }).Distinct();

            ViewBag.name    = cust.name;
            ViewBag.product = cust.product;
            ViewBag.pop     = true;
            List <string> dict = new List <string>();

            foreach (var x in myResult)
            {
                string result = x.name + " придбав підписку " + x.product;
                dict.Add(result);
            }
            ViewBag.data  = dict;
            ViewBag.count = dict.Count();
            return(View());
        }
Esempio n. 12
0
 public ActionResult AddOrder(Order order)
 {
     db.Orders.Add(order);
     db.SaveChanges();
     return(View("../Perfect"));
 }
Esempio n. 13
0
 public ActionResult AddProduct(Product product)
 {
     db.Products.Add(product);
     db.SaveChanges();
     return(View("Index"));
 }
Esempio n. 14
0
 public ActionResult AddUser(User user)
 {
     db.Users.Add(user);
     db.SaveChanges();
     return(View("../Perfect"));
 }
Esempio n. 15
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
Esempio n. 16
0
 public void Delete(T entity)
 {
     _entities.Remove(entity);
     _context.SaveChanges();
 }