public ActionResult Create(sdtoCompany objcompany, HttpPostedFileBase Logo)
        {
            if (ModelState.IsValid)
            {
                var validImageTypes = new string[]
                                        {
                                            "image/gif",
                                            "image/jpeg",
                                            "image/pjpeg",
                                            "image/png"
                                        };

                if (Logo == null || Logo.ContentLength == 0)
                {
                    ModelState.AddModelError("Logo", "This field is required");
                }
                else if (Logo != null && !validImageTypes.Contains(Logo.ContentType))
                {
                    ModelState.AddModelError("Logo", "Please choose either a GIF, JPG or PNG image");
                }
                else
                {
                    objcompany.CreatedOn = DateTime.Now;
                    objcompany.ModifiedOn = DateTime.Now;

                    if (objcompany.Address != null)
                    {
                        objcompany.Address.CreatedOn = objcompany.CreatedOn;
                    }

                    if (objcompany.Contacts != null)
                    {
                        objcompany.Contacts.CreatedOn = objcompany.CreatedOn;
                    }

                    objcompany.Contacts = db.Contacts.Add(objcompany.Contacts);
                    objcompany.Address = db.Address.Add(objcompany.Address);

                    objcompany = db.Companies.Add(objcompany);
                    db.SaveChanges();
                    if (Logo != null)
                    {
                        FileUpload(objcompany.CompanyId, Logo);

                        System.IO.FileInfo fInfo = new FileInfo(ViewBag.CompanyLogoFile);
                        fInfo.CopyTo(Path.Combine(fInfo.Directory.FullName, objcompany.CompanyId + ".logo"), true);
                        fInfo.Delete();
                    }
                    // objcompany.LogoUrl = ViewBag.CompanyLogoFile
                    return RedirectToAction("Index");
                }
            }

            ViewBag.AddressId = new SelectList(db.Address, "AddressId", "Address1", objcompany.AddressId);
            ViewBag.ContactId = new SelectList(db.Contacts, "ContactId", "ContactName", objcompany.ContactId);
            return View(objcompany);
        }
        public ActionResult Edit(sdtoCompany objcompany, HttpPostedFileBase Logo)
        {
            if (ModelState.IsValid)
            {
                objcompany.ModifiedOn = DateTime.Now;

                if (objcompany.Address != null)
                {
                    objcompany.Address.AddressId = objcompany.AddressId;
                    objcompany.Address.ModifiedOn = DateTime.Now;
                    objcompany.Address.ModifiedBy = objcompany.ModifiedBy;
                }

                if (objcompany.Contacts != null)
                {
                    objcompany.Contacts.ContactId = objcompany.ContactId;
                    objcompany.Contacts.ModifiedOn = DateTime.Now;
                    objcompany.Contacts.ModifiedBy = objcompany.ModifiedBy;
                }

                if (Logo != null)
                {
                    FileUpload(objcompany.CompanyId, Logo);

                    System.IO.FileInfo fInfo = new FileInfo(ViewBag.CompanyLogoFile);
                    fInfo.CopyTo(Path.Combine(fInfo.Directory.FullName, objcompany.CompanyId + ".logo"), true);
                    fInfo.Delete();

                    objcompany.LogoUrl = "ContentUpload/Company/" + objcompany.CompanyId + ".logo";
                }

                db.Contacts.Attach(objcompany.Contacts);
                db.Address.Attach(objcompany.Address);
                db.Companies.Attach(objcompany);

                db.Entry<sdtoContact>(objcompany.Contacts).State = EntityState.Modified;
                db.Entry<sdtoAddress>(objcompany.Address).State = EntityState.Modified;
                db.Entry<sdtoCompany>(objcompany).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.AddressId = new SelectList(db.Address, "AddressId", "Address1", objcompany.AddressId);
            ViewBag.ContactId = new SelectList(db.Contacts, "ContactId", "ContactName", objcompany.ContactId);
            return View(objcompany);
        }