示例#1
0
        public ActionResult Add(ContactView contactView)
        {
            //TODO: use auto-mapper
            var contact = new Contact();

            contact.ContactAddress = contactView.ContactAddress;
            contact.ContactEmail = contactView.ContactEmail;
            contact.ContactName = contactView.ContactName;
            contact.ContactMidName = contactView.ContactMidName;
            contact.ContactSurname = contactView.ContactSurname;
            contact.ContactPhoneNumber = contactView.ContactPhoneNumber;

            var id = int.Parse(contactView.ContactTypeID);
            contact.ContactType = _contactTypeLogic.GetContactTypeById(id);

            //TODO: fix default login admin 
            var authorId = WebSecurity.CurrentUserId;
            contact.User = _userLogic.GetUserById(authorId);

            _contactLogic.AddContact(contact);

            return RedirectToAction("Index");
        }
示例#2
0
        public ActionResult Edit(ContactView contactView)
        {
            var contact = new Contact();
            //TODO: auto mapping
            contact.ContactId = contactView.ContactId;
            contact.ContactAddress = contactView.ContactAddress;
            contact.ContactEmail = contactView.ContactEmail;
            contact.ContactName = contactView.ContactName;
            contact.ContactMidName = contactView.ContactMidName;
            contact.ContactSurname = contactView.ContactSurname;
            contact.ContactPhoneNumber = contactView.ContactPhoneNumber;

            var id = int.Parse(contactView.ContactTypeID);
            var type = _contactTypeLogic.GetContactTypeById(id);
            contact.ContactType = type;

            var authorId = WebSecurity.CurrentUserId;
            var user = _userLogic.GetUserById(authorId);
            contact.User = user;

            _contactLogic.EditContact(contact);

            return RedirectToAction("Index");
        }
示例#3
0
        //TODO: Tips
        //inlect
        //dependensy injection 
        //auto mapping 

        public ActionResult Edit(int id)
        {
            var сontact = _contactLogic.GetContactById(id);

            var types = _contactTypeLogic.GetContactTypes();

            ViewBag.ContactTypes = (from i in types
                select new SelectListItem {Selected = false, Text = i.ContactTypeName, Value = i.ContactTypeName})
                .ToList();

            //TODO: make ViewBag for drop down list
            var view = new ContactView();

            view.ContactName = сontact.ContactName;
            view.ContactSurname = сontact.ContactSurname;
            view.ContactMidName = сontact.ContactMidName;
            view.ContactEmail = сontact.ContactEmail;
            view.ContactAddress = сontact.ContactAddress;
            view.ContactId = сontact.ContactId;
            view.ContactPhoneNumber = сontact.ContactPhoneNumber;
            view.ContactTypeName = _contactTypeLogic.GetContactTypes();

            var l = view.ContactTypeName.Select(x =>
                new SelectListItem
                {
                    Text = x.ContactTypeName.ToString(),
                    Value = x.ContactTypeId.ToString()
                }).ToList();
            view.ContactTypeList = l;

            //TODO: clean view

            return View(view);
        }