Пример #1
0
        //
        // GET: /Presentation/Survey/Details/5

        public ActionResult Details(string id)
        {
            if (User.Identity.Name.ToLower() != "admin")
            {
                if (User.Identity.Name != id)
                {
                    throw new Exception("invalid user, must be " + User.Identity.Name+" id="+id);
                }
            }

            ViewBag.CurrentItem = "survey-details";

            using (var context = new LibraryContainer())
            {
                var customer = context.Customer.Include("Survey").First(c => c.Name == id);
                //customer.Survey.SurveyItems.Load();
                if (customer.Survey !=null)
                {
                    var survey = context.Survey.Include("SurveyItems").FirstOrDefault(s => s.Id == customer.Survey.Id);
                    return View(survey);
                }

                return View();
            }
        }
Пример #2
0
        //
        // GET: /Presentation/Layout/Edit/5

        public ActionResult Edit(int id)
        {
            using (var context = new LibraryContainer())
            {
                var layout = context.Layout.First(l => l.Id == id);
                return View(layout);
            }
        }
Пример #3
0
        //
        // GET: /Presentation/Note/Edit/5

        public ActionResult Edit(int id)
        {
            using (var context = new LibraryContainer())
            {
                var note = context.Note.First(n => n.Id == id);
                return View(note);
            }
        }
Пример #4
0
        //
        // GET: /Presentation/Layout/

        public ActionResult Index()
        {
            using (var context = new LibraryContainer())
            {
                var layouts = context.Layout.ToList();
                return View(layouts);
            }
        }
Пример #5
0
 private static string GetUserTitle(string userName)
 {
     using (var context = new LibraryContainer())
     {
         var customer = context.Customer.First(c => c.Name == userName);
         return customer.Title;
     }
 }
Пример #6
0
 public ActionResult Edit(int id)
 {
     using (var context = new LibraryContainer())
     {
         var comment = context.Comment.First(c => c.Id == id);
         return View(comment);
     }
 }
Пример #7
0
        //
        // GET: /Presentation/Comment/

        public ActionResult Index(int id)
        {
            using (var context = new LibraryContainer())
            {
                var product = context.Product.Include("Comments").First(p => p.Id == id);
                return View(product);
            }
        }
Пример #8
0
        //
        // GET: /Presentation/Note/Details/5

        public ActionResult Details(int id)
        {
            ViewBag.CurrentItem = "note-details";
            using (var context = new LibraryContainer())
            {
                var note = context.Note.First(n => n.Id == id);
                return View(note);
            }
        }
Пример #9
0
        //
        // GET: /Presentation/Note/

        public ActionResult Index()
        {
            using (var context = new LibraryContainer())
            {
                var notes = context.Note.ToList();
                ViewBag.CurrentItem = "notes";
                return View(notes);
            }
        }
Пример #10
0
        //
        // GET: /Presentation/Survey/Create

        public ActionResult Create()
        {
            using (var context = new LibraryContainer())
            {
                var customers = context.Customer.Include("Survey").Where(c => c.Name != "admin" && c.Survey == null).ToList();
                ViewBag.Customers = customers;
                return View();
            }
        }
Пример #11
0
 public ActionResult Edit(int id)
 {
     using (var context = new LibraryContainer())
     {
         //var customer = context.Customer.Include("Surveys").First(c => c.Name == id);
         var survay = context.Survey.First(s => s.Id == id);
         return View(survay);
     }
 }
Пример #12
0
        //
        // GET: /Presentation/Survey/

        public ActionResult Index()
        {
            using (var context = new LibraryContainer())
            {
                var survays = context.Survey.Include("Customer").Include("SurveyItems").ToList();
                ViewBag.CurrentItem = "survey";
                return View(survays);
            }
        }
Пример #13
0
 public ActionResult Create(int id)
 {
     using (var context = new LibraryContainer())
     {
         var product = context.Product.First(p => p.Id == id);
         ViewBag.productId = product.Id;
         //var comment = new Comment {Product = product};
         return View();
     }
 }
Пример #14
0
 public ActionResult Edit(int id, FormCollection form)
 {
     using (var context = new LibraryContainer())
     {
         var comment = context.Comment.First(c => c.Id == id);
         TryUpdateModel(comment, new[] {"Text"});
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Пример #15
0
 public ActionResult Delete(int id)
 {
     using (var context = new LibraryContainer())
     {
         var comment = context.Comment.First(c => c.Id == id);
         context.DeleteObject(comment);
         context.SaveChanges();
         return RedirectToAction("Index");
     }
 }
Пример #16
0
        //
        // GET: /Presentation/Category/

        public ActionResult Index()
        {
            using (var context = new LibraryContainer())
            {
                var categories = context.Category.ToList();

                ViewBag.CurrentItem = "picture-lib";
                return View(categories);
            }
        }
Пример #17
0
        public ActionResult Edit(int id, FormCollection form)
        {
            using (var context = new LibraryContainer())
            {
                var survay = context.Survey.First(s => s.Id == id);

                TryUpdateModel(survay, new[] { "Title", "Date" });
                survay.Description = HttpUtility.HtmlDecode(form["Description"]);
                context.SaveChanges();
                return RedirectToAction("Index");
            }
        }
Пример #18
0
        public ActionResult Index()
        {
            using (var context = new LibraryContainer())
            {

                var customers = context.Customer.Include("ProductSets").ToList();

                //string[] users = Roles.GetUsersInRole("Customers");
                
                ViewBag.CurrentItem = "customer";

                return View(customers);
            }

        }
Пример #19
0
        public ActionResult AddProductSet(string customerId, FormCollection form)
        {
            using (var context = new LibraryContainer())
            {
                var customer = context.Customer.Include("ProductSets").First(c => c.Name == customerId);

                var productSet = new ProductSet();

                TryUpdateModel(productSet, new[] { "Title" });
                customer.ProductSets.Add(productSet);

                context.SaveChanges();

                return RedirectToAction("Index", "Customer");
            }
        }
Пример #20
0
        //
        // GET: /Presentation/UserCabinet/Details/5
        //[Authorize(Roles = "Administrators")]
        public ActionResult Details(string id, string layout,  FormCollection form, string set)
        {
            if (User.Identity.Name != "admin")
            {
                if (User.Identity.Name != id)
                {
                    throw new Exception();
                }
            }

            ViewBag.CurrentItem = "customer-details";
            
            var productSet = set;

            using (var context = new LibraryContainer())
            {
                var customer = context.Customer.Include("ProductSets").First(c => c.Name == id);

                foreach (var set1 in customer.ProductSets)
                {
                    set1.Products.Load();
                }

                var layouts = context.Layout.ToList();
                layouts.Insert(0, new Layout { Name = "", Title = "Все" });
                ViewBag.Layouts = layouts;

                ViewBag.Layout = layout;


                if (string.IsNullOrEmpty(productSet))
                {
                    var pset = customer.ProductSets.OrderBy(ps => ps.Title).FirstOrDefault();
                    if (pset != null)
                    {
                        productSet = pset.Id.ToString();
                    }
                }


                ViewBag.ProductSetId = productSet;


                return View(customer);
            }
        }
Пример #21
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                using (var context = new LibraryContainer())
                {
                    var layout = context.Layout.First(l => l.Id == id);
                    TryUpdateModel(layout, new[] { "Name", "Title" });
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Пример #22
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                using (var context = new LibraryContainer())
                {
                    var layout = new Layout();
                    TryUpdateModel(layout, new[] { "Name", "Title" });
                    context.AddToLayout(layout);
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Пример #23
0
        public ActionResult Create(FormCollection form)
        {
            try
            {
                using (var context = new LibraryContainer())
                {
                    var note = new Note();
                    TryUpdateModel(note, new[] { "Title", "Date" });
                    note.Text = HttpUtility.HtmlDecode(form["Text"]);
                    context.AddToNote(note);
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
Пример #24
0
        public ActionResult Create(int productId, FormCollection form)
        {
            using (var context = new LibraryContainer())
            {
                var product = context.Product.First(p => p.Id == productId);
                var comment = new Comment {Date = DateTime.Now};
                TryUpdateModel(comment, new[] {"Text"});

                var customer = context.Customer.First(c => c.Name == User.Identity.Name);
                
                comment.CustomerId = customer.Id;
                comment.CustomerName = customer.Name;
                comment.CustomerTitle = customer.Title;

                product.Comments.Add(comment);
                
                context.SaveChanges();

                return RedirectToAction("Index");
            }
        }
Пример #25
0
        public ActionResult Create(RegisterNewCustomerModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    string email = model.UserName + "@domain.com";
                    MembershipCreateStatus createStatus;
                    Membership.CreateUser(model.UserName, "cde32wsx", email, null, null, true, null, out createStatus);
                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        if (!Roles.RoleExists("Customers"))
                            Roles.CreateRole("Customers");
                        if (!Roles.IsUserInRole(model.UserName, "Customers"))
                            Roles.AddUserToRole(model.UserName, "Customers");

                        using (var context = new LibraryContainer())
                        {
                            var customer = new Customer { Name = model.UserName, Title = model.UserTitle};
                            context.AddToCustomer(customer);
                            context.SaveChanges();
                        }

                        return RedirectToAction("Index", "Customer", new { area = "Presentation" });
                    }
                    else
                    {
                        ModelState.AddModelError("", ErrorCodeToString(createStatus));
                    }
                }
                return View(model);
            }
            catch
            {
                return View(model);
            }
        }
Пример #26
0
        //
        // GET: /Presentation/Category/Details/5

        public ActionResult Details(string id, string layout, FormCollection form, string set)
        {
            using (var context = new LibraryContainer())
            {
                var productSet = set;
                var layouts = context.Layout.ToList();
                layouts.Insert(0, new Layout { Name = "", Title = "Все" });
                ViewBag.Layouts = layouts;

                ViewBag.Layout = layout;

                var category = context.Category.Include("Products").First(c => c.Name == id);

                //category.Products.Load();

                //IEnumerable<Product> products = category.Products.Where(p => p.Layout.Name == layout);

                //category.Products.Clear();

                //foreach (var product in products)
                //{
                //    category.Products.Add(product);
                //}

                var customer = context.Customer.Include("ProductSets").First(c => c.Name == User.Identity.Name);

                ViewBag.ProductSets = customer.ProductSets.ToList();

                //ViewBag.ProductContainers = client.ProductContainers.Select(pc => new SelectListItem { Text = pc.Title, Value = pc.Id.ToString() }).ToList();

                //if (string.IsNullOrEmpty(productSet))
                //{
                //    var ps = client.ProductSets.FirstOrDefault();
                //    if (ps != null)
                //    {
                //        productSet = ps.Id.ToString();
                //    }
                //}

                foreach (var product in category.Products)
                {
                    product.Comments.Load();
                }


                if (!string.IsNullOrEmpty(productSet))
                {
                    var productsSet = customer.ProductSets.First(ps => ps.Id == Convert.ToInt32(productSet));
                    var productsInProductSet = context.ProductSet.Include("Products").First(ps => ps.Id == productsSet.Id);
                    foreach (var product in category.Products)
                    {
                        foreach (var p in productsInProductSet.Products)
                        {
                            if (product.Id == p.Id)
                                product.Selected = true;
                        }
                    }
                }
                else
                {
                    var productsSet = customer.ProductSets.OrderBy(c => c.Title).FirstOrDefault();
                    if (productsSet != null)
                    {
                        productSet = productsSet.Id.ToString();
                        var productsInProductSet = context.ProductSet.Include("Products").First(ps => ps.Id == productsSet.Id);
                        foreach (var product in category.Products)
                        {
                            foreach (var p in productsInProductSet.Products)
                            {
                                if (product.Id == p.Id)
                                    product.Selected = true;
                            }
                        }
                    }
                }

                ViewBag.ProductSetId = productSet;

                ViewBag.CurrentItem = "picture-lib-details";
                return View(category);
            }
        }
Пример #27
0
        public ActionResult Delete(int id)
        {

            using (var context = new LibraryContainer())
            {

                var category = context.Category.Include("Products").First(c => c.Id == id);
                while (category.Products.Any())
                {
                    var product = category.Products.First();
                    ImageHelper.DeleteImage(product.ImageSource);
                    product.Layout = null;
                    context.DeleteObject(product);
                }

                ImageHelper.DeleteImage(category.ImageSource);
                context.DeleteObject(category);

                context.SaveChanges();

            }

            return RedirectToAction("Index");
        }
Пример #28
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                using (var context = new LibraryContainer())
                {
                    var category = context.Category.First(c => c.Id == id);
                    TryUpdateModel(category, new[] { "Name", "Title" });
                    context.SaveChanges();

                    return RedirectToAction("Index");
                }
            }
            catch
            {
                return View();
            }
        }
Пример #29
0
        //
        // GET: /Presentation/Category/Edit/5

        public ActionResult Edit(int id)
        {
            using (var context = new LibraryContainer())
            {
                var category = context.Category.First(c => c.Id == id);
                return View(category);
            }
        }
Пример #30
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                using (var context = new LibraryContainer())
                {
                    var category = new Category { ImageSource = "" };
                    TryUpdateModel(category, new[] { "Name", "Title" });

                    context.AddToCategory(category);
                    context.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }