Exemple #1
0
        public IActionResult AgentList()
        {
            if (HttpContext.Session.GetString("UserRole") == "1")
            {
                var a    = _context.Agents.AsNoTracking().ToList();
                var sent = new List <AgentVm>();
                int c    = 1;
                foreach (var item in a)
                {
                    AgentVm o = new AgentVm()
                    {
                        Address = item.Address,
                        Name    = item.Name,
                        Mobile  = item.Mobile,
                        DOB     = item.DOB,
                        AgentId = item.AgentId,
                        Serial  = c
                    };
                    sent.Add(o);

                    c++;
                }
                return(View(sent));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemple #2
0
        public static AgentVm GetAgentInfo(int id)
        {
            AgentVm carrVmObj = new AgentVm();

            if (id == 0)
            {
                ContactPersonVm contactVm = new ContactPersonVm();
                carrVmObj.ContactPersons.Add(contactVm);
            }
            else
            {
                EasyFreightEntities db = new EasyFreightEntities();
                Agent carrDbObj        = db.Agents.Include("AgentContacts")
                                         .Where(x => x.AgentId == id).FirstOrDefault();

                Mapper.CreateMap <Agent, AgentVm>().IgnoreAllNonExisting();
                Mapper.Map(carrDbObj, carrVmObj);

                Mapper.CreateMap <AgentContact, ContactPersonVm>().IgnoreAllNonExisting()
                .ForMember(x => x.FkValue, opts => opts.MapFrom(scr => scr.AgentId));

                ContactPersonVm contactVm;
                foreach (var item in carrDbObj.AgentContacts)
                {
                    contactVm = new ContactPersonVm();
                    Mapper.Map(item, contactVm);
                    carrVmObj.ContactPersons.Add(contactVm);
                }
            }
            return(carrVmObj);
        }
Exemple #3
0
        public IActionResult AddNewAgent(AgentVm a)
        {
            Agent b = new Agent()
            {
                AgentId = a.AgentId,
                Address = a.Address,
                DOB     = a.DOB,
                Mobile  = a.Mobile,
                Name    = a.Name
            };

            _context.Agents.Add(b);
            _context.SaveChanges();

            User us = new User()
            {
                Password   = b.Name + (b.Mobile % 100).ToString(),
                RoleTypeId = 2,
                UserName   = b.Name + (b.Mobile % 100).ToString() + "@whitespace.com",
                UserId     = 0,
            };

            _context.Users.Add(us);
            _context.SaveChanges();



            ModelState.Clear();
            return(View());
        }
Exemple #4
0
        /// <summary>
        /// Add Agent To The Accounting chart ..
        /// If note type = 1 "Debit" add under A/R .. else 2 "Credit" addd under A/P
        /// </summary>
        /// <param name="agentId">Agent Id</param>
        /// <param name="agentType">Agent Note Type</param>
        /// <returns></returns>
        public static string AddAgentToChart(int agentId, byte agentType)
        {
            string parentAccountId = "", accountId;

            if (agentType == 1) //Debit Note .. A/R
            {
                parentAccountId = ((int)AccountingChartEnum.Agents).ToString();
            }
            else
            {
                parentAccountId = ((int)AccountingChartEnum.Agents).ToString();
            }

            AgentVm agentObj  = AgentHelper.GetAgentInfo(agentId);
            string  accNameEn = agentObj.AgentNameEn;
            string  accNameAr = string.IsNullOrEmpty(agentObj.AgentNameAr) ? agentObj.AgentNameEn : agentObj.AgentNameAr;

            //Add new accountId to the chart
            accountId = AccountingChartHelper
                        .AddAccountToChart(accNameEn, accNameEn, parentAccountId);

            AccountingChartHelper.AddAccountIdToObj(accountId, "Agent", agentId, "AgentId");

            return(accountId);
        }
Exemple #5
0
        public IActionResult DeleteAgent(AgentVm a)
        {
            var item = _context.Agents.Where(s => s.AgentId == a.AgentId).FirstOrDefault();

            _context.Agents.Remove(item);
            _context.SaveChanges();


            return(RedirectToAction("AgentList"));
        }
Exemple #6
0
        public IActionResult UpdateAgent(AgentVm item)
        {
            Agent o = new Agent()
            {
                Address = item.Address,
                Name    = item.Name,
                Mobile  = item.Mobile,
                DOB     = item.DOB,
                AgentId = item.AgentId,
            };

            _context.Agents.Update(o);
            _context.SaveChanges();



            return(RedirectToAction("AgentList"));
        }
Exemple #7
0
        public IActionResult AgentDetails(int id)
        {
            if (HttpContext.Session.GetString("UserRole") == "1")
            {
                var item = _context.Agents.AsNoTracking().Where(s => s.AgentId == id).FirstOrDefault();

                AgentVm o = new AgentVm()
                {
                    Address = item.Address,
                    Name    = item.Name,
                    Mobile  = item.Mobile,
                    DOB     = item.DOB,
                    AgentId = item.AgentId,
                };


                return(View(o));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemple #8
0
        public ActionResult Add(int id = 0)
        {
            #region Check Rights
            bool hasRights;
            if (id == 0)
            {
                hasRights = AdminHelper.CheckUserAction(ScreenEnum.Agent, ActionEnum.Add);
            }
            else
            {
                hasRights = AdminHelper.CheckUserAction(ScreenEnum.Agent, ActionEnum.Edit);
            }

            if (!hasRights)
            {
                return(RedirectToAction("UnAuthorized", "Home", new { area = "" }));
            }

            #endregion

            ViewData["CityList"] = ListCommonHelper.GetCityGrouped();
            AgentVm agentObj = AgentHelper.GetAgentInfo(id);
            return(View(agentObj));
        }
Exemple #9
0
        public static string AddEditAgent(AgentVm carrVm)
        {
            int    carrId          = carrVm.AgentId;
            string isSaved         = "true";
            EasyFreightEntities db = new EasyFreightEntities();
            Agent carrDb;
            List <AgentContact> dbContactList = new List <AgentContact>();

            if (carrId == 0) //Add new case
            {
                carrDb = new Agent();
            }
            else
            {
                carrDb = db.Agents.Include("AgentContacts").Where(x => x.AgentId == carrId).FirstOrDefault();
                //delete any removed contact on the screen
                dbContactList = carrDb.AgentContacts.ToList();
                try
                {
                    //Get contact Ids sent from the screen
                    List <int> contactVmIds = carrVm.ContactPersons.Select(x => x.ContactId).ToList();
                    var        contactDel   = dbContactList.Where(x => !contactVmIds.Contains(x.ContactId)).ToList();

                    foreach (var item in contactDel)
                    {
                        db.AgentContacts.Remove(item);
                    }
                }
                catch { }
            }

            Mapper.CreateMap <AgentVm, Agent>().IgnoreAllNonExisting();
            Mapper.Map(carrVm, carrDb);



            if (carrId == 0)
            {
                Random rand = new Random();
                carrDb.AgentCode = rand.Next(10000).ToString();
                db.Agents.Add(carrDb);
            }

            Mapper.CreateMap <ContactPersonVm, AgentContact>().IgnoreAllNonExisting()
            .ForMember(x => x.AgentId, opts => opts.MapFrom(scr => scr.FkValue));

            AgentContact carrContactDb;

            if (carrVm.ContactPersons != null && carrVm.ContactPersons.Count > 0)
            {
                foreach (var item in carrVm.ContactPersons.Where(x => !string.IsNullOrEmpty(x.ContactName)))
                {
                    if (item.ContactId == 0)
                    {
                        carrContactDb = new AgentContact();
                    }
                    else
                    {
                        int contVmId = item.ContactId;
                        carrContactDb = dbContactList.Where(x => x.ContactId == contVmId).FirstOrDefault();
                    }

                    Mapper.Map(item, carrContactDb);

                    if (item.ContactId == 0)
                    {
                        carrDb.AgentContacts.Add(carrContactDb);
                    }
                }
            }
            try
            {
                db.SaveChanges();
            }
            catch (DbEntityValidationException e)
            {
                isSaved = "false " + e.Message;
            }
            catch (Exception e)
            {
                isSaved = "false " + e.Message;
            }

            return(isSaved);
        }
Exemple #10
0
        public ActionResult AddEditAgent(AgentVm agentVm)
        {
            string isSaved = AgentHelper.AddEditAgent(agentVm);

            return(Json(isSaved));
        }
        public ApiResponse <LocationResVm, ApiData> GetLocations()
        {
            LocationResVm result = new LocationResVm();

            List <AgentVm> mainOfficeLocations       = new List <AgentVm>();
            List <AgentVm> searchedLocationsWithMO   = new List <AgentVm>();
            List <AgentVm> searchedLocationsExternal = new List <AgentVm>();

            AgentVm mainOfficeAgent = GetMainOfficeAgent();

            //Get all the lcoations for mainoffice(exluding mainoffice agent)
            mainOfficeLocations = LocationsForMainOffice(_authUser.MainOfficeAgentId);

            searchedLocationsWithMO.Add(mainOfficeAgent);
            searchedLocationsWithMO.AddRange(mainOfficeLocations);

            if (AuthIntegration.GetMainOfficeId().ToString() != string.Empty &&
                _authUser.Status.Equals(UserStatus.External) && _authUser.UserAgentList != null &&
                _authUser.UserAgentList.Count != 0)
            {
                UserAgentActivity userAgent = (_authUser.UserAgentList != null
                    ? _authUser.UserAgentList.FirstOrDefault()
                    : new UserAgentActivity());

                // if user has access to all locations
                if (_authUser.AllLocationsAllowed)
                {
                    searchedLocationsExternal = LocationsForMainOffice(_authUser.MainOfficeAgentId).ToList();
                }
                //// if user is main office user and has the AgentAssistfunctionality
                else if (IsUserAgentAssistFuncionality(_authUser) &&
                         userAgent.AgentId.Equals(AuthIntegration.GetMainOfficeId()))
                {
                    searchedLocationsExternal = searchedLocationsWithMO;
                }
                else
                {
                    // if user is either sublevel or location user then

                    foreach (UserAgentActivity u in _authUser.UserAgentList)
                    {
                        var agent = mainOfficeLocations.Find(ag => ag.id.ToString() == u.AgentId);
                        if (agent != null)
                        {
                            if ((HierarchyLevel)agent.hierarchyLevel == HierarchyLevel.SubLevel)
                            {
                                //passing the agentid inplace of the sublevelagentid field
                                var locations = LocationsForMainOffice(_authUser.MainOfficeAgentId, agent.id);
                                searchedLocationsExternal.AddRange(locations);
                            }
                            else
                            {
                                searchedLocationsExternal.Add(agent);
                            }
                        }
                    }
                }
                result.Agents = searchedLocationsExternal;
            }
            else
            {
                result.Agents = searchedLocationsWithMO;
            }

            return(new ApiResponse <LocationResVm, ApiData>
            {
                ResponseData = result,
                BusinessMetadata = MapperHelper.SetResponseProperties(null, DataSource.PartnerService)
            });
        }