public ActionResult Create(int leadid)
        {
            Web.ViewModel.AccountInformationViewModel acc = new Web.ViewModel.AccountInformationViewModel();

            var username = HttpContext.User.Identity.Name;

            acc.user   = _UserRepository.GetUserByUsername(username);
            acc.leadId = leadid;
            Lead accountlead = _LeadRepository.LeadByLeadID(leadid);

            acc.lead = accountlead;
            // int userid = acc.lead.AssignedAAUserId;

            User assignedaauser = new User();

            assignedaauser = _UserRepository.GetUserById(accountlead.AssignedAAUserId);
            acc.assignedaa = assignedaauser;
            if (assignedaauser != null)
            {
                acc.AAName = assignedaauser.FirstName + " " + assignedaauser.LastName;
            }

            User assignedsauser = new User();

            assignedsauser = _UserRepository.GetUserById(accountlead.AssignedSAUserId);
            acc.assignedsa = assignedsauser;
            if (assignedsauser != null)
            {
                acc.SAName = assignedsauser.FirstName + " " + assignedsauser.LastName;
                acc.EID    = assignedsauser.FirstName.Substring(0, 1) + assignedsauser.LastName.Substring(0, 1) + "1000" + assignedsauser.UserId.ToString();
            }

            var term   = _EquipmentRepository.GetEquipmentByType("Terminal");
            var pinpad = _EquipmentRepository.GetEquipmentByType("Pinpad");
            var equip  = _EquipmentRepository.GetEquipmentByType("Check");

            IList <string> terms  = new List <string>();
            IList <string> pins   = new List <string>();
            IList <string> equips = new List <string>();

            foreach (var t in term)
            {
                terms.Add(t.Name);
            }
            acc.terminals = acc.terminals.Concat(terms);

            foreach (var p in pinpad)
            {
                pins.Add(p.Name);
            }
            acc.pinpad = acc.pinpad.Concat(pins);

            foreach (var e in equip)
            {
                equips.Add(e.Name);
            }
            acc.equipment = acc.equipment.Concat(equips);
            // uc.AssignedZoneList = _ZoneRepository.Zones.DefaultIfEmpty();//
            return(View(acc));
        }
        public ActionResult Create(Web.ViewModel.AccountInformationViewModel vm)
        {
            Report newRecord  = new Report();
            var    newAccount = vm.account;

            vm.account.ParentLead       = vm.leadId;
            vm.account.AssignedSalesRep = vm.assignedsa.UserId;
            vm.account.AACreator        = vm.assignedaa.UserId;
            var appointmentforlead = _AppointmentRepository.GetAppointmentByLeadId(vm.leadId);

            foreach (var appointment in appointmentforlead)
            {
                if (appointment.Score == "Good")
                {
                    newRecord = _ReportRepository.CheckExistingRecord(appointment.AssignedSalesAgent);
                    newRecord.MonthlyAccounts++;
                    var accountsforlead = _AccountRepository.GetAccountsByLeadId(vm.leadId);
                    if (accountsforlead.Count() == 0)
                    {
                        newRecord.MonthlyCloses++;
                    }
                    _ReportRepository.SaveReports(newRecord);

                    break;
                }
            }
            _AccountRepository.SaveAccounts(newAccount);

            //TO assign status to the lead for which account was created.

            Lead lead = new Lead();

            lead        = _LeadRepository.LeadByLeadID(vm.leadId);
            lead.Status = "Customer";
            _LeadRepository.SaveLead(lead);



            //return RedirectToActionPermanent("Index");
            return(Json(new { redirectToUrl = Url.Action("Index") }));
        }
 public ActionResult Edit(Web.ViewModel.AccountInformationViewModel avm)
 {
     SaveAccountInformation(avm);
     //return Content("Account "+ avm.account.AccountName +" updated to leadID "+ avm.account.ParentLead);
     return(RedirectToActionPermanent("Index"));
 }
 public ActionResult AccountInformation(Web.ViewModel.AccountInformationViewModel avm)
 {
     //SaveAccountInformation(avm);
     return(Content("Contact: " + avm.account.AccountName + " has been saved"));
     //return RedirectToActionPermanent("Index");
 }