Exemple #1
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");
     }
 }
Exemple #2
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");
     }
 }
Exemple #3
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");
            }
        }
Exemple #4
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();
            }
        }
Exemple #5
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();
            }
        }
Exemple #6
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();
            }
        }
Exemple #7
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");
            }
        }
        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);
            }
        }
        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();
            }
        }
Exemple #10
0
        public ActionResult Delete(int id)
        {
            using (var context = new LibraryContainer())
            {
                var survey = context.Survey.Include("SurveyItems").First(s => s.Id == id);
                while (survey.SurveyItems.Any())
                {
                    var si = survey.SurveyItems.First();
                    context.DeleteObject(si);
                }
                context.DeleteObject(survey);

                context.SaveChanges();

                return RedirectToAction("Index");
            }
        }
Exemple #11
0
 public ActionResult Delete(int id, FormCollection collection)
 {
     using (var context = new LibraryContainer())
     {
         var layout = context.Layout.First(l => l.Id == id);
         context.DeleteObject(layout);
         context.SaveChanges();
     }
     return RedirectToAction("Index");
 }
        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");
            }
        }
Exemple #13
0
 public ActionResult DeleteSurveyItem(int id)
 {
     using (var context = new LibraryContainer())
     {
         var surveyItem = context.SurveyItem.Include("Survey").First(si => si.Id == id);
         var surveyId = surveyItem.Survey.Id;
         var survey = context.Survey.Include("Customer").First(s => s.Id == surveyId);
         context.DeleteObject(surveyItem);
         context.SaveChanges();
         return RedirectToAction("Details", "Survey", new { id = survey.Customer.Name });
     }
 }
 public ActionResult EditProductSet(int id, FormCollection form)
 {
     using (var context = new LibraryContainer())
     {
         var productSet = context.ProductSet.Include("Customer").First(ps => ps.Id == id);
         TryUpdateModel(productSet, new[] { "Title" });
         context.SaveChanges();
         //return RedirectToAction("Details", new { id = productSet.Customer.Name });
         return RedirectToAction("Index", "Customer");
     }
 }
 public ActionResult DeleteProductSet(int id)
 {
     using (var context = new LibraryContainer())
     {
         var productSet = context.ProductSet.Include("Products").Include("Customer").First(ps => ps.Id == id);
         var customerName = productSet.Customer.Name;
         ViewBag.CustomerId = productSet.Customer.Name;
         productSet.Products.Clear();
         context.DeleteObject(productSet);
         context.SaveChanges();
         return RedirectToAction("Index", "Customer");
     }
 }
Exemple #16
0
        public ActionResult SaveSurvey(FormCollection form)
        {
            string number = form["inputNumber"];
            string question = form["txtQuestion"];
            int surveyId = Convert.ToInt32(form["surveyId"]);

            try
            {
                if (string.IsNullOrWhiteSpace(number) || string.IsNullOrWhiteSpace(question))
                    return View("NewSurveyItem");
                using (var context = new LibraryContainer())
                {
                    var survey = context.Survey.FirstOrDefault(s => s.Id == surveyId);
                    if (survey == null)
                        return View("NewSurveyItem");
                    var surveyItem = new SurveyItem { Survey = survey, Number = number, Question = question };
                    context.AddToSurveyItem(surveyItem);
                    context.SaveChanges();
                    return View("NewSurveyItem", surveyItem);
                }
            }
            catch
            {
                return View("NewSurveyItem");
            }
        }
Exemple #17
0
 public ActionResult Edit(int id, FormCollection form)
 {
     try
     {
         using (var context = new LibraryContainer())
         {
             var note = context.Note.First(n => n.Id == id);
             TryUpdateModel(note, new[] { "Title", "Date" });
             note.Text = HttpUtility.HtmlDecode(form["Text"]);
             context.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Exemple #18
0
 public string UpdateSurvey(int id, FormCollection form)
 {
     using (var context = new LibraryContainer())
     {
         var surveyItem = context.SurveyItem.First(s => s.Id == id);
         surveyItem.Question = form["taQuestion_" + id];
         surveyItem.Number = form["tbNumber_" + id];
         context.SaveChanges();
         return surveyItem.Number + "###" + surveyItem.Question;
     }
 }
Exemple #19
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();
            }
        }
Exemple #20
0
        public ActionResult Delete(int id)
        {
            using (var context = new LibraryContainer())
            {
                var customer = context.Customer.Include("ProductSets").First(c => c.Id == id);
                string userName = customer.Name;

                while (customer.ProductSets.Any())
                {
                    var productContainer = customer.ProductSets.First();
                    context.DeleteObject(productContainer);
                    context.SaveChanges();
                }

                context.DeleteObject(customer);

                Membership.DeleteUser(userName);

                context.SaveChanges();

                return RedirectToAction("Index");
            }

        }
Exemple #21
0
        public ActionResult Create(FormCollection form, int customerId)
        {
            try
            {
                using (var context = new LibraryContainer())
                {
                    var customer = context.Customer.First(c => c.Id == customerId);

                    var survey = new Survey
                                     {
                                         Date = DateTime.Now,
                                         Title = form["Title"],
                                         Description = HttpUtility.HtmlDecode(form["Description"]),
                                         Customer = customer
                                     };

                    context.AddToSurvey(survey);
                    context.SaveChanges();

                    return RedirectToAction("Index");
                }
            }
            catch
            {
                return View();
            }
        }
Exemple #22
0
        public bool SaveAnswer(FormCollection form)
        {
            int surveyId = Convert.ToInt32(form["surveyId"]);

            try
            {
                using (var context = new LibraryContainer())
                {
                    var survey = context.Survey.Include("SurveyItems").First(s => s.Id == surveyId);
                    foreach (var item in survey.SurveyItems)
                    {
                        item.Answer = form["taAnswer_" + item.Id];
                        item.Note = form["taNote_" + item.Id];
                    }
                    context.SaveChanges();
                }
            }
            catch
            {
                return false;
            }

            return true;
        }
Exemple #23
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");
        }
Exemple #24
0
        //
        // GET: /Presentation/Note/Delete/5

        public ActionResult Delete(int id)
        {
            using (var context = new LibraryContainer())
            {
                var note = context.Note.First(n => n.Id == id);
                context.DeleteObject(note);
                context.SaveChanges();
            }
            return RedirectToAction("Index");
        }