// POST: SellersAccount/Create

        public ActionResult CreateSeller(SellersView model)
        {
            model.UserID = User.Identity.GetUserId();
            if (ModelState.IsValid)
            {
                try
                {
                    var newData = new Seller
                    {
                        UserID       = model.UserID,
                        FirtstName   = model.FirtstName,
                        Signature    = model.Signature,
                        SellerNumber = model.SellerNumber,
                        SellerEmail  = model.SellerEmail,
                        LastName     = model.LastName,
                        SellerType   = model.SellerType
                    };

                    newData.ProfilePhoto = FileController.PostFile(model.ProfilePhoto, "ProfilePhoto", "ProfilePhoto");



                    //Call Post Method
                    Seller ob = APIMethods.APIPost <Seller>(newData, "Sellers");


                    if (ob.SellerType == "Retailer")
                    {
                        return(RedirectToAction("CreateRetialer"));
                    }
                    else if (ob.SellerType == "Auctioneer")
                    {
                        return(RedirectToAction("CreateAuctioneer"));
                    }
                    else
                    {
                        return(RedirectToAction("CreatePrivate"));
                    }
                }
                catch (Exception E)
                {
                    throw new Exception(E.ToString());
                }
            }
            else
            {
                return(View());
            }
        }
        public ActionResult CreateRetialer(RetailerView model)
        {
            model.UserID = User.Identity.GetUserId();
            if (ModelState.IsValid)
            {
                try
                {
                    var newData = new Retailer
                    {
                        UserID               = model.UserID,
                        RetailerName         = model.RetailerName,
                        Signature            = model.Signature,
                        CompanyContactNumber = model.CompanyContactNumber,
                        CompanyEmail         = model.CompanyEmail,
                        CompanyDescription   = model.CompanyDescription,
                        Branch               = model.Branch
                    };

                    newData.CompaynLogoPath = FileController.PostFile(model.CompaynLogoPath, "CompaynLogoPath", "CompaynLogoPath");



                    //Call Post Method
                    Retailer ob = APIMethods.APIPost <Retailer>(newData, "Retailers");
                    return(RedirectToAction("AddAddress"));
                }
                catch (Exception E)
                {
                    throw new Exception(E.ToString());
                }
            }
            else
            {
                return(View());
            }
        }
        public async Task <ActionResult> CreateProperty(PropertyView model)
        {
            if (ModelState.IsValid && model.SellerSigniture)
            {
                try
                {
                    var config = new MapperConfiguration(cfg => {
                        cfg.CreateMap <PropertyView, Property>();
                    });

                    IMapper  mapper  = config.CreateMapper();
                    Property NewProp = mapper.Map <PropertyView, Property>(model);
                    NewProp.SellerID = User.Identity.GetUserId();
                    if (NewProp.TitleDeedPath == "")
                    {
                        NewProp.TitleDeedPath = "N/A";
                    }
                    if (NewProp.BedRooms == null)
                    {
                        NewProp.BedRooms = 0;
                    }
                    if (NewProp.FloorSize == null)
                    {
                        NewProp.FloorSize = 0;
                    }
                    if (NewProp.YardSize == null)
                    {
                        NewProp.YardSize = 0;
                    }
                    if (NewProp.Reserve == null)
                    {
                        NewProp.Reserve = 0;
                    }
                    if (NewProp.Garages == null)
                    {
                        NewProp.Garages = 0;
                    }
                    if (NewProp.OpeningBid == null)
                    {
                        NewProp.OpeningBid = 0;
                    }
                    if (NewProp.TaxesAndRate == null)
                    {
                        NewProp.TaxesAndRate = 0;
                    }
                    if (NewProp.levies == null)
                    {
                        NewProp.levies = 0;
                    }

                    NewProp.MandateSingedDate = DateTime.Now;
                    NewProp.MandateExpireDate = DateTime.Now.AddDays(90);
                    NewProp.TaxesAndRates     = FileController.PostFile(model.TaxesAndRates, "TaxesAndRates", "TaxesAndRates");
                    NewProp.PlansPath         = FileController.PostFile(model.PlansPath, "Plans", "Plans");
                    //  NewProp.TitleDeedPath = FileController.PostFile(model.TitleDeedPath, "Titledeeds", "Titledeeds");
                    NewProp.HOARules = FileController.PostFile(model.HOARules, "HOARules", "HOARules");

                    //Call Post Method
                    Property ob = APIMethods.APIPost <Property>(NewProp, "Properties");

                    SendGridService ser = new SendGridService();

                    /*EmailMessageInfo msg = new EmailMessageInfo() {
                     *  FromEmailAddress = "*****@*****.**",
                     *  ToEmailAddress = model.Seller.SellerEmail,
                     *  EmailSubject ="New Property listing.",
                     *  EmailBody = "Property: Title-"+model.Title+"/n Address- "+model.Address+"/n Youre listing will be reviewed and you will be notified Accordingly."
                     * };
                     * //          await ser.Send(msg);
                     *
                     * EmailMessageInfo msgAdmin = new EmailMessageInfo() {
                     *  FromEmailAddress = "*****@*****.**",
                     *  ToEmailAddress = model.Seller.SellerEmail,
                     *  EmailSubject ="New Property listing.",
                     *  EmailBody = "Property: Title-"+model.Title+"/n Address- "+model.Address+"./n Property listed by "+model.Seller.FirtstName+" "+model.Seller.LastName
                     * };
                     * await ser.Send(msgAdmin);*/

                    return(RedirectToAction("AddPhoto", new { id = ob.PropertyID }));
                }
                catch (Exception E)
                {
                    throw new Exception(E.Message);
                }
            }
            else
            {
                return(View(model));
            }
        }