Exemplo n.º 1
0
        public ActionResult Delete(int id)
        {
            var _db = new ContactBUS().GetContacts();
            var contact = new ContactBUS().GetContact(id);

            _db.Remove(contact);
            return RedirectToAction("List");
        }
Exemplo n.º 2
0
        public ActionResult Insert(Contact contact)
        {
            
            if (!ModelState.IsValid)
            {
                return View(contact);
            }

            var _db = new ContactBUS().GetContacts();

            contact.Id = _db.Max(c => c.Id) + 1;
            _db.Add(contact);

            return RedirectToAction("Detail", new { id = contact.Id });
        }
        public ActionResult Filter(FilterViewModel model)
        {
            var logic = new ContactBUS();

            var groupings =  logic.Contacts.Select(c => c.LuckyNumber.HasValue ? c.LuckyNumber.Value : 0 ).GroupBy(item => item);

            model.LuckyNumberMap = groupings.ToDictionary(gr => gr.Key, gr => gr.Count());

            var results = new ContactBUS().Contacts.Where(c => c.LuckyNumber == model.SelectedLuckyNumber || (model.SelectedLuckyNumber == 0 && !c.LuckyNumber.HasValue));
            
            model.Contacts = results.ToList();


            return View(model);
        }
Exemplo n.º 4
0
        public ActionResult Insert(Contact contact, string prefix)
        {
            if (!ModelState.IsValid)
                return View(contact);

            var _db = new ContactBUS().GetContacts();

            contact.Id = _db.Max(c => c.Id) + 1;
            _db.Add(contact);

            prefix = contact.FirstName.Substring(0, 1);

            return RedirectToAction("List", new {id = contact.Id, prefix});

        }
Exemplo n.º 5
0
 public ActionResult Edit(Contact contact)
 {
     var _db = new ContactBUS().GetContacts();
     if(!ModelState.IsValid)
         return View(contact);
     foreach (var c in _db)
     {
         if (c.Id == contact.Id)
         {
             c.LastName = contact.LastName;
             c.FirstName = contact.FirstName;
             c.Email = contact.Email;
             break;
         }
     }
     return RedirectToAction("Detail", new { contact.Id });
 }
Exemplo n.º 6
0
 public System.Collections.Generic.IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
 {
     //throw new NotImplementedException();
     var list = new List<ValidationResult>();
     var contacts = new ContactBUS().GetContacts().Where(c => c.Email.ToLower() == this.Email.ToLower());
     if (contacts.Any() && contacts.Single().Id != this.Id)
     {
         list.Add(new ValidationResult("Email Address already exists"));
     }
     else
     {
         if(contacts.Any())
             list.Add(new ValidationResult("Email Address already exists"));
     }
     
     return list;
 }
Exemplo n.º 7
0
        public System.Collections.Generic.IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            var list = new List<ValidationResult>();
            var contacts = new ContactBUS().GetContacts().Where(c => c.Email.ToLower() == this.Email.ToLower());
            if (this.Id > 0)
            {
                if (contacts.Any() && contacts.Single().Id != this.Id)
                    list.Add(new ValidationResult("Email exists"));
            }
            else
            {
                if(contacts.Any())
                    list.Add(new ValidationResult("Email exists"));
            }

            return list;

        }
Exemplo n.º 8
0
        public ActionResult List(string prefix)
        {
            var _db = new ContactBUS().GetContacts();
            var contacts = _db.Where(c => prefix == null || c.FirstName.ToLower().StartsWith(prefix.ToLower())).ToList();
            var letters = _db.Select(c => c.FirstName.Substring(0, 1).ToUpper()).Distinct().OrderBy(letter => letter).ToList();
            var model = new ContactViewModel
            {
                SelectedLetters = letters,
                Contacts = contacts,
                SelectedLetter = prefix != null ? prefix.ToUpper() : String.Empty
            };
            
            //var model = new List<Contact>();
            //foreach(var contact in _db)
            //    if(prefix == null || contact.FirstName.ToLower().StartsWith(prefix.ToLower()))
            //        model.Add(contact);

            return View(model);
        }
        public ActionResult Filter(FilterViewModel model)
        {
            var logic = new ContactBUS();

            var groupings = logic.Contacts.Select(
                c => c.LuckyNumber.HasValue ? c.LuckyNumber.Value : 0).GroupBy(item => item);

            model.LuckyNumberMap = groupings.ToDictionary(gr => gr.Key, gr => gr.Count());

            var results =

            model.Contacts = new ContactBUS().Contacts.Where(c => c.LuckyNumber == model.SelectedLuckyNumber).ToList();

            //model.LuckyNumberMap = new ContactBUS().GetContacts().Where(c=>c.LuckyNumber.HasValue).GroupBy(c => c.LuckyNumber).ToDictionary(gr => gr.Key.Value, gr => gr.Count());

            //if (new ContactBUS().GetContacts().Where(c => !c.LuckyNumber.HasValue).Any())
            //    model.LuckyNumberMap.Add(0, new ContactBUS().GetContacts().Where(c => !c.LuckyNumber.HasValue).Count());

            return View(model);
        }
Exemplo n.º 10
0
        public ActionResult Edit(Contact contact, string prefix)
        {
            var _db = new ContactBUS().GetContacts();
            if(!ModelState.IsValid)
                return View(contact);

            foreach (var c in _db)
            {
                if (c.Id == contact.Id)
                {
                    c.LastName = contact.LastName;
                    c.FirstName = contact.FirstName;
                    c.Email = contact.Email;
                    break;
                }
            }

            prefix = contact.FirstName.Substring(0, 1);
            return RedirectToAction("List", new { id = contact.Id, prefix });
        }
Exemplo n.º 11
0
        public ActionResult List(int id, string prefix)
        {
            //if (prefix == null)
            //{
            //    prefix = 'A'.ToString();
            //}
            var _db = new ContactBUS().GetContacts();
            var contacts = _db.Where(c => prefix == null || c.FirstName.ToLower().StartsWith(prefix.ToLower())).ToList();
            
            var letters = _db.Select(c => c.FirstName.Substring(0, 1).ToUpper()).Distinct().OrderBy(letter => letter).ToList();

            var model = new ContactViewModel
            {
                Contacts = contacts,
                SelectedLetters = letters,
                SelectedLetter = prefix != null ? prefix.ToUpper() : String.Empty,
                lastId = id
            };
            return View(model);
        }
Exemplo n.º 12
0
 public ContactController()
 {
     _contactBUS = new ContactBUS();
 }
Exemplo n.º 13
0
        public ActionResult Detail(int id)
        {
            var contact = new ContactBUS().GetContact(id);
            if (contact == null)
                return RedirectToAction("NotFound");

            return View(contact);
        }
Exemplo n.º 14
0
 public ActionResult Delete(int id, string prefix)
 {
     var _db = new ContactBUS().GetContacts();
     var contact = new ContactBUS().GetContact(id);
     _db.Remove(contact);
     return RedirectToAction("List", new { id = contact.Id, prefix });
 }
 public ActionResult Index()
 {
     var user = new ContactBUS().GetHighestLuckyNumber();
     return View(user);
 }
Exemplo n.º 16
0
 public ActionResult Edit(int id)
 {
     var model = new ContactBUS().GetContact(id);
     return View(model);
 }
 public ActionResult List(int low, int high)
 {
     var users = new ContactBUS().GetUsersByLuckyNumberRange(low, high);
     return View(users);
 }
 public ActionResult LuckyNumberView(int luckyNumber)
 {
     var users = new ContactBUS().GetLuckyNumber(luckyNumber);
     return View(users);
 }