public IActionResult Create(vmAgent vmAgent)
        {
            if (ModelState.IsValid)
            {
                Agent agent = new Agent()
                {
                    CompanyName     = vmAgent.CompanyName,
                    AppointmentDate = vmAgent.AppointmentDate,
                    Area            = vmAgent.Area,
                    Name            = vmAgent.Name,
                    Phone           = vmAgent.Phone,
                    Email           = vmAgent.Email,
                    Address         = vmAgent.Address,
                    Country         = vmAgent.Country,
                    DateOfBirth     = vmAgent.DateOfBirth,
                    BillByBill      = vmAgent.BillByBill,

                    OnAccount     = vmAgent.OnAccount,
                    HasCommission = vmAgent.HasCommission,
                };
                if (vmAgent.PaymentMethod == "onAccount")
                {
                    agent.OnAccount = true;
                }
                else if (vmAgent.PaymentMethod == "billByBill")
                {
                    agent.BillByBill = true;
                }

                if (vmAgent.Photo != null)
                {
                    var fileName = ContentDispositionHeaderValue.Parse(vmAgent.Photo.ContentDisposition).FileName.Trim('"').Replace(" ", string.Empty);

                    var path = _imagePath.GetImagePath(fileName, "Agents", vmAgent.Name);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        vmAgent.Photo.CopyTo(stream);
                    }
                    agent.Photo = _imagePath.GetImagePathForDb(path);
                }

                _work.Agent.Add(agent);

                bool isSaved = _work.Save() > 0;

                if (isSaved)
                {
                    return(Json(true));
                }
            }
            return(Json(false));
        }
        public IActionResult EditView(int id)
        {
            var     agent   = _work.Agent.Get(id);
            vmAgent vmAgent = new vmAgent();

            vmAgent.Id            = agent.Id;
            vmAgent.Name          = agent.Name;
            vmAgent.CompanyName   = agent.CompanyName;
            vmAgent.Country       = agent.Country;
            vmAgent.DateOfBirth   = agent.DateOfBirth;
            vmAgent.Email         = agent.Email;
            vmAgent.Phone         = agent.Phone;
            vmAgent.OnAccount     = agent.OnAccount;
            vmAgent.BillByBill    = agent.BillByBill;
            vmAgent.HasCommission = agent.HasCommission;
            vmAgent.NID           = agent.NID;
            vmAgent.Address       = agent.Address;
            return(PartialView("EditView", vmAgent));
        }
        public IActionResult Edit(vmAgent vmAgent)
        {
            var agent = _work.Agent.Get(vmAgent.Id);

            if (ModelState.IsValid)
            {
                agent.CompanyName   = vmAgent.CompanyName;
                agent.Name          = vmAgent.Name;
                agent.Country       = vmAgent.Country;
                agent.DateOfBirth   = vmAgent.DateOfBirth;
                agent.Email         = vmAgent.Email;
                agent.Phone         = vmAgent.Phone;
                agent.OnAccount     = vmAgent.OnAccount;
                agent.BillByBill    = vmAgent.BillByBill;
                agent.HasCommission = vmAgent.HasCommission;
                agent.NID           = vmAgent.NID;
                agent.Address       = vmAgent.Address;
                if (vmAgent.Photo != null)
                {
                    var fileName = ContentDispositionHeaderValue.Parse(vmAgent.Photo.ContentDisposition).FileName.Trim('"').Replace(" ", string.Empty);
                    var path     = _imagePath.GetImagePath(fileName, "Agents", vmAgent.Name).Replace(" ", string.Empty);

                    using (var stream = new FileStream(path, FileMode.Create))
                    {
                        vmAgent.Photo.CopyTo(stream);
                    }
                    agent.Photo = _imagePath.GetImagePathForDb(path);
                }
                _work.Agent.Update(agent);

                bool isSaved = _work.Save() > 0;

                if (isSaved)
                {
                    return(Json(true));
                }
            }
            return(PartialView("EditView"));
        }