public ActionResult Create(long Id = 0)
        {
            ViewBag.SuccessMessage = "";

            AccountFormModel accountFormModel = new AccountFormModel();

            accountFormModel = getDropDownValues(accountFormModel);

            if(Id != 0)
            {
                Account account = accountService.GetAccount(Id);
                accountFormModel = AutoMapper.Mapper.Map<Account, AccountFormModel>(account);
                if(account.Type != null)
                    accountFormModel.Type = (int)Enum.Parse(typeof(TypeEnum), account.Type);
                if(account.Industry != null)
                accountFormModel.Industry = (int)Enum.Parse(typeof(IndustryEnum), account.Industry);
            }

            accountFormModel = getDropDownValues(accountFormModel);

            return View("AccountCreate", accountFormModel);
        }
        public ActionResult Details(long Id)
        {
            AccountFormModel accountDetails = new AccountFormModel();

            Account account = accountService.GetAccount(Id);

            accountDetails = AutoMapper.Mapper.Map<Account, AccountFormModel>(account);

            if (accountDetails.AssignedToUserGroup == UserGroup.group)
            {
                accountDetails.AssignedToName = groupService.GetGroup(accountDetails.AssignedTo) != null ? groupService.GetGroup(accountDetails.AssignedTo).Name : string.Empty;
            }
            else
            {
                accountDetails.AssignedToName = userService.GetUser(accountDetails.AssignedTo) != null ? userService.GetUser(accountDetails.AssignedTo).Name : string.Empty;
            }

            accountDetails.TypeName = account.Type;
            accountDetails.IndustryName = account.Industry;
            if(account.MemberOf != null)
                accountDetails.MemberOfName = ((MemberOfEnum)account.MemberOf).ToString();

            return View("AccountDetails", accountDetails);
        }
        private AccountFormModel getDropDownValues(AccountFormModel accountFormModel)
        {
            IEnumerable<MemberOfEnum> Memberofsrc = Enum.GetValues(typeof(MemberOfEnum))
                                                    .Cast<MemberOfEnum>();

            accountFormModel.MemberOfList = from src in Memberofsrc
                                        select new SelectListItem
                                        {
                                            Text = src.ToString(),
                                            Value = ((int)src).ToString()
                                        };

            IEnumerable<TypeEnum> sourcetypes = Enum.GetValues(typeof(TypeEnum))
                                                     .Cast<TypeEnum>();

            accountFormModel.TypeList = from src in sourcetypes
                                           select new SelectListItem
                                           {
                                               Text = src.ToString(),
                                               Value = ((int)src).ToString()
                                           };

            IEnumerable<IndustryEnum> industrytypes = Enum.GetValues(typeof(IndustryEnum))
                                                      .Cast<IndustryEnum>();

            accountFormModel.IndustryList = from src in industrytypes
                                           select new SelectListItem
                                           {
                                               Text = src.ToString(),
                                               Value = ((int)src).ToString()
                                           };

            if (accountFormModel.AssignedToUserGroup == UserGroup.group)
            {
                var groups = groupService.GetGroups();

                List<SelectListItem> grpItems = new List<SelectListItem>();

                grpItems.AddRange(groups.OrderBy(grp => grp.Name)
                .Select(grp =>
               new SelectListItem
               {
                   Selected = (grp.ID == accountFormModel.AssignedTo),
                   Text = grp.Name,
                   Value = grp.ID.ToString()
               }));

                accountFormModel.GrpUserList = grpItems;
            }
            else
            {
                accountFormModel.AssignedToUserGroup = UserGroup.user;

                var users = userService.GetUsers();

                List<SelectListItem> items = new List<SelectListItem>();
                items.AddRange(users.OrderBy(user => user.Name)
                 .Select(user =>
                new SelectListItem
                {
                    Selected = (user.ID == accountFormModel.AssignedTo),
                    Text = user.Name,
                    Value = user.ID.ToString()
                }));

                accountFormModel.GrpUserList = items;
            }

            return accountFormModel;
        }
        public ActionResult Create(AccountFormModel accountmodel)
        {
            try
            {
                Account account = AutoMapper.Mapper.Map<AccountFormModel, Account>(accountmodel);
                account.Type = ((TypeEnum)accountmodel.Type).ToString();
                account.Industry = ((IndustryEnum)accountmodel.Industry).ToString();

                if (ModelState.IsValid)
                {
                    if (account.ID == 0)
                    {
                        accountService.CreateAccount(account);
                    }
                    else
                    {
                        accountService.EditAccount(account);
                    }
                    ViewBag.successMessage = "Account Saved Successfully";
                    ViewBag.errorMessage = "";
                }
                else
                {
                    string validationErrors = string.Join(",", ModelState.Values.Where(E => E.Errors.Count > 0)
                    .SelectMany(E => E.Errors).Select(E => E.ErrorMessage).ToArray());

                    ViewBag.successMessage = "";
                    ViewBag.errorMessage = validationErrors;
                }
                accountmodel = getDropDownValues(accountmodel);
            }
            catch (Exception ex)
            {
                ViewBag.successMessage = "";
                ViewBag.errorMessage = string.Format("Error in Account Save : {0}", ex.Message);
                accountmodel = getDropDownValues(accountmodel);
            }

            return View("AccountCreate", accountmodel);
        }