public ActionResult Create([Bind(Include = "Id,Company_Name,Company_Website,Company_Title,Company_Phone1,Company_Phone2,Company_EMail,Company_Address,Owner_NameSurname,Owner_Title,Owner_EMail,Owner_Phone,Owner_Phone2")] Portfolio_Company portfolio_Company)
        {
            if (ModelState.IsValid)
            {
                db.Portfolio_Company.Add(portfolio_Company);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(portfolio_Company));
        }
        public ActionResult Create(Portfolio_Customer portfolio_Customer)
        {
            if (ModelState.IsValid)
            {
                db.Portfolio_Customer.Add(portfolio_Customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(portfolio_Customer));
        }
        public ActionResult Create(Portfolio_Banks portfolio_Banks)
        {
            if (ModelState.IsValid)
            {
                portfolio_Banks.UpdateDate=DateTime.Now;
                db.Portfolio_Banks.Add(portfolio_Banks);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(portfolio_Banks);
        }
        public ActionResult Create(Portfolio_Personal portfolio_Personal, HttpPostedFileBase Image)
        {
            if (ModelState.IsValid)
            {
                var path = "";

                if (Image != null)
                {
                    if (Image.ContentLength > 0)
                    {
                        //for checking uploaded file is image or not

                        if (Path.GetExtension(Image.FileName).ToLower() == ".jpg"

                            || Path.GetExtension(Image.FileName).ToLower() == ".png"

                            || Path.GetExtension(Image.FileName).ToLower() == ".gif"

                            || Path.GetExtension(Image.FileName).ToLower() == ".jpeg")
                        {
                            path = Path.Combine(Server.MapPath("~/UploadImage/Personal"), Image.FileName);

                            Image.SaveAs(path);

                            ViewBag.UploadSuccess = true;
                        }
                    }
                }

                Portfolio_Personal personal = new Portfolio_Personal();
                personal.Image           = "/UploadImage/Personal/" + Image.FileName;
                personal.Name            = portfolio_Personal.Name;
                personal.Surname         = portfolio_Personal.Surname;
                personal.Phone1          = portfolio_Personal.Phone1;
                personal.Phone2          = portfolio_Personal.Phone2;
                personal.BirthDate       = portfolio_Personal.BirthDate;
                personal.BirthPlace      = portfolio_Personal.BirthPlace;
                personal.Driving_Licence = portfolio_Personal.Driving_Licence;
                personal.Address         = portfolio_Personal.Address;
                personal.TC         = portfolio_Personal.TC;
                personal.Department = portfolio_Personal.Department;
                personal.UserId     = portfolio_Personal.UserId;

                db.Portfolio_Personal.Add(personal);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(portfolio_Personal));
        }
        public ActionResult CustomerProcess(CustomerModelView customer)
        {
            if (ModelState.IsValid)
            {
                if (customer.Id == null)
                {
                    if (customer.c_Name == null && customer.c_Surname == null)
                    {
                        Portfolio_CustomerRequest pcus = new Portfolio_CustomerRequest();
                        pcus.City           = customer.cr_City;
                        pcus.Country        = customer.cr_Country;
                        pcus.FinishDate     = customer.cr_FinishDate;
                        pcus.C_Id           = customer.c_Id;
                        pcus.FloorChange    = customer.cr_FloorChange;
                        pcus.Housing        = customer.cr_Housing;
                        pcus.Land           = customer.cr_Land;
                        pcus.MaxArea        = customer.cr_MaxArea;
                        pcus.MinArea        = customer.cr_MinArea;
                        pcus.MaxPrice       = customer.cr_MaxPrice;
                        pcus.MinPrice       = customer.cr_MinPrice;
                        pcus.Note           = customer.cr_Note;
                        pcus.Status         = customer.cr_Status;
                        pcus.Office         = customer.cr_Office;
                        pcus.Transformation = customer.cr_Transformation;
                        db.Portfilio_CustomerRequest.Add(pcus);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        Portfolio_Customer cus = new Portfolio_Customer();
                        cus.Name    = customer.c_Name;
                        cus.Surname = customer.c_Surname;
                        cus.EMail   = customer.c_EMail;
                        cus.Phone2  = customer.c_Phone2;
                        cus.Phone1  = customer.c_Phone1;
                        db.Portfolio_Customer.Add(cus);
                        db.SaveChanges();
                        var customerId =
                            db.Portfolio_Customer.Where(x => x.EMail == customer.c_EMail && x.Name == customer.c_Name &&
                                                        x.Surname == customer.c_Surname)
                            .Select(x => x.Id)
                            .FirstOrDefault();

                        Portfolio_CustomerRequest pcus = new Portfolio_CustomerRequest();
                        pcus.City           = customer.cr_City;
                        pcus.Country        = customer.cr_Country;
                        pcus.FinishDate     = customer.cr_FinishDate;
                        pcus.C_Id           = customerId;
                        pcus.FloorChange    = customer.cr_FloorChange;
                        pcus.Housing        = customer.cr_Housing;
                        pcus.Land           = customer.cr_Land;
                        pcus.MaxArea        = customer.cr_MaxArea;
                        pcus.MinArea        = customer.cr_MinArea;
                        pcus.MaxPrice       = customer.cr_MaxPrice;
                        pcus.MinPrice       = customer.cr_MinPrice;
                        pcus.Note           = customer.cr_Note;
                        pcus.Status         = customer.cr_Status;
                        pcus.Office         = customer.cr_Office;
                        pcus.Transformation = customer.cr_Transformation;
                        db.Portfilio_CustomerRequest.Add(pcus);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    Portfolio_CustomerRequest pcus =
                        db.Portfilio_CustomerRequest.Where(x => x.Id == customer.Id).FirstOrDefault();
                    pcus.City           = customer.cr_City;
                    pcus.Country        = customer.cr_Country;
                    pcus.FinishDate     = customer.cr_FinishDate;
                    pcus.C_Id           = customer.c_Id;
                    pcus.FloorChange    = customer.cr_FloorChange;
                    pcus.Housing        = customer.cr_Housing;
                    pcus.Land           = customer.cr_Land;
                    pcus.MaxArea        = customer.cr_MaxArea;
                    pcus.MinArea        = customer.cr_MinArea;
                    pcus.MaxPrice       = customer.cr_MaxPrice;
                    pcus.MinPrice       = customer.cr_MinPrice;
                    pcus.Note           = customer.cr_Note;
                    pcus.Status         = customer.cr_Status;
                    pcus.Office         = customer.cr_Office;
                    pcus.Transformation = customer.cr_Transformation;

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            AddItemDropDownList();
            return(View(customer));
        }
        public ActionResult PortfolioProcess(PortfolioModelView portfoliomodel, IEnumerable <HttpPostedFileBase> pd_Image, IEnumerable <HttpPostedFileBase> pc_AuthorityDocument)//Veriler list şeklinde gonderilecek alınırken bölüm bölüm alınıp ilgili tabloya kayıt yapılacak
        {
            if (ModelState.IsValid)
            {
                if (portfoliomodel.Id == null)
                {
                    //var personal_id =
                    //    db.Portfolio_Personal.Where(
                    //            x => x.Name == portfoliomodel.pp_Source)
                    //        .Select(x => x.Id)
                    //        .FirstOrDefault();
                    //Yeni portföy kayıdı

                    if (portfoliomodel.pcus_Surname != null && portfoliomodel.pcus_Name != null)
                    {
                        Portfolio_Customer pcus = new Portfolio_Customer();
                        pcus.EMail   = portfoliomodel.pcus_EMail;
                        pcus.Name    = portfoliomodel.pcus_Name;
                        pcus.Surname = portfoliomodel.pcus_Surname;
                        pcus.Phone1  = portfoliomodel.pcus_Phone1;
                        pcus.Seller  = true;
                        db.Portfolio_Customer.Add(pcus);
                        db.SaveChanges();
                        var sorgu =
                            db.Portfolio_Customer.FirstOrDefault(
                                x => x.Name == portfoliomodel.pcus_Name && x.EMail == portfoliomodel.pcus_EMail).Id;

                        portfoliomodel.pg_Customer_Id = sorgu;
                    }
                    Portfolio_Contract pc = new Portfolio_Contract();
                    //pc.Pg_Id = pg_Id;
                    pc.StartDate           = portfoliomodel.pc_StartDate;
                    pc.FinishDate          = portfoliomodel.pc_FinishDate;
                    pc.Buyer_Rate          = portfoliomodel.pc_Buyer_Rate;
                    pc.Seller_Rate         = portfoliomodel.pc_Seller_Rate;
                    pc.MinPrice            = portfoliomodel.pc_MinPrice;
                    pc.MaxPrice            = portfoliomodel.pc_MaxPrice;
                    pc.Buyer_ServicePrice  = portfoliomodel.pc_Buyer_ServicePrice;
                    pc.Seller_ServicePrice = portfoliomodel.pc_Seller_ServicePrice;
                    pc.ContractNumber      = portfoliomodel.pc_ContractNumber;
                    string path = Server.MapPath("~/UploadImage/" + portfoliomodel.pg_Header);
                    Directory.CreateDirectory(path);
                    if (portfoliomodel.pc_AuthorityDocument != null)
                    {
                        foreach (var file in pc_AuthorityDocument)
                        {
                            if (file.ContentLength > 0)
                            {
                                var filename  = Path.GetFileName(file.FileName);
                                var kayityeri = Path.Combine(path, filename);
                                pc.AuthorityDocument += "/UploadImage/" + portfoliomodel.pg_Header + " " + filename + ", ";
                                file.SaveAs(kayityeri);
                            }
                        }
                    }

                    db.Portfolio_Contract.Add(pc);
                    db.SaveChanges();
                    var contractId = db.Portfolio_Contract.Where(
                        x => x.ContractNumber == pc.ContractNumber && x.Buyer_ServicePrice == pc.Buyer_ServicePrice &&
                        x.FinishDate == pc.FinishDate).Select(x => x.Id).FirstOrDefault();
                    portfoliomodel.pg_Contract_Id = contractId;

                    Portfolio_General pg = new Portfolio_General();
                    pg.Type_State   = portfoliomodel.pg_Type_State;
                    pg.Area_Brut    = portfoliomodel.pg_Area_Brut;
                    pg.Status       = 0;
                    pg.Contract_Id  = portfoliomodel.pg_Contract_Id;
                    pg.Area_Net     = portfoliomodel.pg_Area_Net;
                    pg.Comment      = portfoliomodel.pg_Comment;
                    pg.Credit       = portfoliomodel.pg_Credit;
                    pg.Description  = portfoliomodel.pg_Description;
                    pg.Header       = portfoliomodel.pg_Header;
                    pg.Personal_Id  = User.Identity.GetUserId();
                    pg.Price        = portfoliomodel.pg_Price;
                    pg.Date         = portfoliomodel.pg_Date;
                    pg.Type         = portfoliomodel.pg_Type;
                    pg.Subscription = portfoliomodel.pg_Subscription;
                    pg.Price_Type   = portfoliomodel.pg_Price_Type;
                    pg.Customer_Id  = portfoliomodel.pg_Customer_Id;
                    db.Portfolio_General.Add(pg);
                    db.SaveChanges();
                    var pg_Id =
                        db.Portfolio_General.Where(
                            x => x.Comment == portfoliomodel.pg_Comment && x.Header == portfoliomodel.pg_Header)
                        .Select(x => x.Id).FirstOrDefault();

                    Portfolio_Detail pd = new Portfolio_Detail();
                    pd.Balcony_Number  = portfoliomodel.pd_Balcony_Number;
                    pd.Bathroom_Number = portfoliomodel.pd_Bathroom_Number;
                    pd.Building_Age    = portfoliomodel.pd_Building_Age;
                    pd.Building_Floor  = portfoliomodel.pd_Building_Floor;
                    pd.Floor           = portfoliomodel.pd_Floor;
                    pd.Floor_Change    = portfoliomodel.pd_Floor_Change;

                    pd.Heating = portfoliomodel.pd_Heating;

                    pd.Room_Number   = portfoliomodel.pd_Room_Number;
                    pd.Saloon_Number = portfoliomodel.pd_Saloon_Number;
                    pd.Status        = portfoliomodel.pd_Status;
                    pd.Pg_Id         = pg_Id;
                    path             = Server.MapPath("~/UploadImage/" + portfoliomodel.pg_Header);
                    Directory.CreateDirectory(path);
                    if (portfoliomodel.pd_Image != null)
                    {
                        foreach (var file in pd_Image)
                        {
                            if (file.ContentLength > 0)
                            {
                                var filename  = Path.GetFileName(file.FileName);
                                var kayityeri = Path.Combine(path, filename);
                                pd.Image += "/UploadImage/" + portfoliomodel.pg_Header + " " + filename + ", ";
                                file.SaveAs(kayityeri);
                            }
                        }
                    }
                    db.Portfolio_Detail.Add(pd);
                    db.SaveChanges();

                    Portfolio_Address pa = new Portfolio_Address();
                    pa.Address   = portfoliomodel.pa_Address;
                    pa.City      = portfoliomodel.pa_City;
                    pa.Country   = portfoliomodel.pa_Country;
                    pa.District  = portfoliomodel.pa_District;
                    pa.Latitude  = portfoliomodel.pa_Latitude;
                    pa.Longitude = portfoliomodel.pa_Longitude;
                    pa.Pg_Id     = pg_Id;
                    pa.Site_Name = portfoliomodel.pa_Site_Name;
                    db.Portfolio_Address.Add(pa);
                    db.SaveChanges();

                    Portfolio_ExtraDetail pe = new Portfolio_ExtraDetail();
                    pe.Pg_Id       = pg_Id;
                    pe.North       = portfoliomodel.pe_North;
                    pe.Sourth      = portfoliomodel.pe_Sourth;
                    pe.East        = portfoliomodel.pe_East;
                    pe.West        = portfoliomodel.pe_West;
                    pe.Fiber       = portfoliomodel.pe_Fiber;
                    pe.Satellite   = portfoliomodel.pe_Satellite;
                    pe.Cable_tv    = portfoliomodel.pe_Cable_tv;
                    pe.Adsl        = portfoliomodel.pe_Adsl;
                    pe.Fax         = portfoliomodel.pe_Fax;
                    pe.Phone       = portfoliomodel.pe_Phone;
                    pe.WiFi        = portfoliomodel.pe_WiFi;
                    pe.Elevator    = portfoliomodel.pe_Elevator;
                    pe.Pool        = portfoliomodel.pe_Pool;
                    pe.Child_Park  = portfoliomodel.pe_Child_Park;
                    pe.Garage      = portfoliomodel.pe_Garage;
                    pe.Garden      = portfoliomodel.pe_Garden;
                    pe.Fire_Stairs = portfoliomodel.pe_Fire_Stairs;
                    pe.Securityman = portfoliomodel.pe_Securityman;
                    pe.Generator   = portfoliomodel.pe_Generator;
                    pe.Camera      = portfoliomodel.pe_Camera;
                    pe.Fire_Alarm  = portfoliomodel.pe_Fire_Alarm;
                    pe.Thief_Alarm = portfoliomodel.pe_Thief_Alarm;
                    pe.Sea         = portfoliomodel.pe_Sea;
                    pe.Throat      = portfoliomodel.pe_Throat;
                    pe.Mountain    = portfoliomodel.pe_Mountain;
                    pe.City        = portfoliomodel.pe_City;
                    pe.Nature      = portfoliomodel.pe_Nature;
                    pe.Lake        = portfoliomodel.pe_Lake;

                    db.Portfolio_ExtraDetail.Add(pe);
                    db.SaveChanges();



                    return(RedirectToAction("Index", "Portfolio"));
                }
                else
                {
                    //Bu kısım güncelleme kısmı olacak
                    if (portfoliomodel.pcus_Surname != null && portfoliomodel.pcus_Name != null)
                    {
                        Portfolio_Customer pcus = new Portfolio_Customer();
                        pcus.EMail   = portfoliomodel.pcus_EMail;
                        pcus.Name    = portfoliomodel.pcus_Name;
                        pcus.Surname = portfoliomodel.pcus_Surname;
                        pcus.Phone1  = portfoliomodel.pcus_Phone1;
                        pcus.Seller  = true;
                        db.Portfolio_Customer.Add(pcus);
                        db.SaveChanges();
                        var sorgu =
                            db.Portfolio_Customer.Where(
                                x => x.Name == portfoliomodel.pcus_Name && x.EMail == portfoliomodel.pcus_EMail).Select(x => x.Id).FirstOrDefault();

                        portfoliomodel.pg_Customer_Id = sorgu;
                    }

                    Portfolio_General pg = db.Portfolio_General.FirstOrDefault(x => x.Id == portfoliomodel.Id);
                    pg.Type_State   = portfoliomodel.pg_Type_State;
                    pg.Area_Brut    = portfoliomodel.pg_Area_Brut;
                    pg.Area_Net     = portfoliomodel.pg_Area_Net;
                    pg.Comment      = portfoliomodel.pg_Comment;
                    pg.Credit       = portfoliomodel.pg_Credit;
                    pg.Description  = portfoliomodel.pg_Description;
                    pg.Header       = portfoliomodel.pg_Header;
                    pg.Personal_Id  = portfoliomodel.pg_Personal_Id;
                    pg.Price        = portfoliomodel.pg_Price;
                    pg.Type         = portfoliomodel.pg_Type;
                    pg.Customer_Id  = portfoliomodel.pg_Customer_Id;
                    pg.Subscription = portfoliomodel.pg_Subscription;
                    pg.Price_Type   = portfoliomodel.pg_Price_Type;
                    db.SaveChanges();
                    //var pg_Id =
                    //    db.Portfolio_General.Where(
                    //            x => x.Comment == portfoliomodel.pg_Comment && x.Header == portfoliomodel.pg_Header)
                    //        .Select(x => x.Id).FirstOrDefault();

                    Portfolio_Detail pd = db.Portfolio_Detail.Where(x => x.Pg_Id == portfoliomodel.Id).FirstOrDefault();
                    pd.Balcony_Number  = portfoliomodel.pd_Balcony_Number;
                    pd.Bathroom_Number = portfoliomodel.pd_Bathroom_Number;
                    pd.Building_Age    = portfoliomodel.pd_Building_Age;
                    pd.Building_Floor  = portfoliomodel.pd_Building_Floor;
                    pd.Floor           = portfoliomodel.pd_Floor;
                    pd.Floor_Change    = portfoliomodel.pd_Floor_Change;

                    pd.Heating       = portfoliomodel.pd_Heating;
                    pd.Room_Number   = portfoliomodel.pd_Room_Number;
                    pd.Saloon_Number = portfoliomodel.pd_Saloon_Number;
                    pd.Status        = portfoliomodel.pd_Status;
                    string path = Server.MapPath("~/UploadImage/" + portfoliomodel.pg_Header);
                    Directory.CreateDirectory(path);
                    if (portfoliomodel.pd_Image != null)
                    {
                        foreach (var file in pd_Image)
                        {
                            if (file.ContentLength > 0)
                            {
                                var filename  = Path.GetFileName(file.FileName);
                                var kayityeri = Path.Combine(path, filename);
                                pd.Image += "/UploadImage/" + portfoliomodel.pg_Header + "/" + filename + ";";
                                file.SaveAs(kayityeri);
                            }
                        }
                    }


                    //pd.Pg_Id = portfoliomodel.Id;
                    db.SaveChanges();

                    Portfolio_Address pa = db.Portfolio_Address.Where(x => x.Pg_Id == portfoliomodel.Id).FirstOrDefault();
                    pa.Address   = portfoliomodel.pa_Address;
                    pa.City      = portfoliomodel.pa_City;
                    pa.Country   = portfoliomodel.pa_Country;
                    pa.District  = portfoliomodel.pa_District;
                    pa.Latitude  = portfoliomodel.pa_Latitude;
                    pa.Longitude = portfoliomodel.pa_Longitude;
                    //pa.Pg_Id = portfoliomodel.pa_Id;
                    pa.Site_Name = portfoliomodel.pa_Site_Name;
                    db.SaveChanges();

                    Portfolio_ExtraDetail pe = db.Portfolio_ExtraDetail.Where(x => x.Pg_Id == portfoliomodel.Id).FirstOrDefault();
                    // pe.Pg_Id = portfoliomodel.pe_Id;
                    pe.North       = portfoliomodel.pe_North;
                    pe.Sourth      = portfoliomodel.pe_Sourth;
                    pe.East        = portfoliomodel.pe_East;
                    pe.West        = portfoliomodel.pe_West;
                    pe.Fiber       = portfoliomodel.pe_Fiber;
                    pe.Satellite   = portfoliomodel.pe_Satellite;
                    pe.Cable_tv    = portfoliomodel.pe_Cable_tv;
                    pe.Adsl        = portfoliomodel.pe_Adsl;
                    pe.Fax         = portfoliomodel.pe_Fax;
                    pe.Phone       = portfoliomodel.pe_Phone;
                    pe.WiFi        = portfoliomodel.pe_WiFi;
                    pe.Elevator    = portfoliomodel.pe_Elevator;
                    pe.Pool        = portfoliomodel.pe_Pool;
                    pe.Child_Park  = portfoliomodel.pe_Child_Park;
                    pe.Garage      = portfoliomodel.pe_Garage;
                    pe.Garden      = portfoliomodel.pe_Garden;
                    pe.Fire_Stairs = portfoliomodel.pe_Fire_Stairs;
                    pe.Securityman = portfoliomodel.pe_Securityman;
                    pe.Generator   = portfoliomodel.pe_Generator;
                    pe.Camera      = portfoliomodel.pe_Camera;
                    pe.Fire_Alarm  = portfoliomodel.pe_Fire_Alarm;
                    pe.Thief_Alarm = portfoliomodel.pe_Thief_Alarm;
                    pe.Sea         = portfoliomodel.pe_Sea;
                    pe.Throat      = portfoliomodel.pe_Throat;
                    pe.Mountain    = portfoliomodel.pe_Mountain;
                    pe.City        = portfoliomodel.pe_City;
                    pe.Nature      = portfoliomodel.pe_Nature;
                    pe.Lake        = portfoliomodel.pe_Lake;

                    db.SaveChanges();

                    Portfolio_Contract pc = db.Portfolio_Contract.FirstOrDefault(x => x.Id == portfoliomodel.pg_Contract_Id);
                    pc.StartDate           = portfoliomodel.pc_StartDate;
                    pc.FinishDate          = portfoliomodel.pc_FinishDate;
                    pc.Buyer_Rate          = portfoliomodel.pc_Buyer_Rate;
                    pc.Seller_Rate         = portfoliomodel.pc_Seller_Rate;
                    pc.MinPrice            = portfoliomodel.pc_MinPrice;
                    pc.MaxPrice            = portfoliomodel.pc_MaxPrice;
                    pc.Buyer_ServicePrice  = portfoliomodel.pc_Buyer_ServicePrice;
                    pc.Seller_ServicePrice = portfoliomodel.pc_Seller_ServicePrice;
                    pc.ContractNumber      = portfoliomodel.pc_ContractNumber;
                    path = Server.MapPath("~/UploadImage/" + portfoliomodel.pg_Header);
                    Directory.CreateDirectory(path);
                    if (portfoliomodel.pc_AuthorityDocument != null)
                    {
                        foreach (var file in pc_AuthorityDocument)
                        {
                            if (file.ContentLength > 0)
                            {
                                var filename  = Path.GetFileName(file.FileName);
                                var kayityeri = Path.Combine(path, filename);
                                pc.AuthorityDocument += "/UploadImage/" + portfoliomodel.pg_Header + " " + filename + ", ";
                                file.SaveAs(kayityeri);
                            }
                        }
                    }
                    db.SaveChanges();

                    return(RedirectToAction("Index", "Portfolio"));
                }
            }

            return(View(portfoliomodel));
        }
        public ActionResult ProjectProcess(ProjectModelView projectmodelview)
        {
            if (ModelState.IsValid)
            {
                if (projectmodelview.Id == null)
                {
                    if (projectmodelview.c_Company_Name == null && projectmodelview.c_Owner_NameSurname == null)
                    {
                        Portfolio_Project prj = new Portfolio_Project();
                        prj.Company_Id          = projectmodelview.p_Company_Id;
                        prj.FinishDate          = projectmodelview.p_FinishDate;
                        prj.Header              = projectmodelview.p_Header;
                        prj.ProjectStatus       = projectmodelview.p_ProjectStatus;
                        prj.Rate                = projectmodelview.p_Rate;
                        prj.Project_Description = projectmodelview.p_Project_Description;
                        prj.Special_Header      = projectmodelview.p_Special_Header;
                        prj.Type                = projectmodelview.p_Type;
                        db.Portfolio_Project.Add(prj);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        Portfolio_Company pcom = new Portfolio_Company();
                        pcom.Owner_EMail       = projectmodelview.c_Owner_EMail;
                        pcom.Company_Name      = projectmodelview.c_Company_Name;
                        pcom.Owner_Phone       = projectmodelview.c_Owner_Phone;
                        pcom.Owner_Title       = projectmodelview.c_Owner_Title;
                        pcom.Owner_NameSurname = projectmodelview.c_Owner_NameSurname;
                        db.Portfolio_Company.Add(pcom);
                        db.SaveChanges();

                        var com_Id =
                            db.Portfolio_Company.Where(
                                x =>
                                x.Owner_NameSurname == projectmodelview.c_Owner_NameSurname &&
                                x.Company_Name == projectmodelview.c_Company_Name)
                            .Select(x => x.Id)
                            .FirstOrDefault();

                        Portfolio_Project prj = new Portfolio_Project();
                        prj.Company_Id          = com_Id;
                        prj.FinishDate          = projectmodelview.p_FinishDate;
                        prj.Header              = projectmodelview.p_Header;
                        prj.ProjectStatus       = projectmodelview.p_ProjectStatus;
                        prj.Rate                = projectmodelview.p_Rate;
                        prj.Project_Description = projectmodelview.p_Project_Description;
                        prj.Special_Header      = projectmodelview.p_Special_Header;
                        prj.Type                = projectmodelview.p_Type;
                        db.Portfolio_Project.Add(prj);
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    Portfolio_Project prj = db.Portfolio_Project.FirstOrDefault(x => x.Id == projectmodelview.Id);
                    prj.Company_Id          = projectmodelview.p_Company_Id;
                    prj.FinishDate          = projectmodelview.p_FinishDate;
                    prj.Header              = projectmodelview.p_Header;
                    prj.ProjectStatus       = projectmodelview.p_ProjectStatus;
                    prj.Rate                = projectmodelview.p_Rate;
                    prj.Project_Description = projectmodelview.p_Project_Description;
                    prj.Special_Header      = projectmodelview.p_Special_Header;
                    prj.Type                = projectmodelview.p_Type;

                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            AddItemDropDownList();
            return(View(projectmodelview));
        }