public bool Create(Company company, UserCompanyRef userCompanyRef, string userId, string logo) { try { if (logo.Length > 10) { var extension = logo.Substring(logo.IndexOf(':') + 1); var extLength = extension.IndexOf(';'); var allLength = extension.Length - extLength; extension = extension.Remove(extLength, allLength); var file = logo.Substring(logo.IndexOf(',') + 1); var bytes = Convert.FromBase64String(file); company.LogoMimeType = extension; company.LogoData = bytes; } userCompanyRef.UserId = userId; userCompanyRef.CompanyId = company.CompanyId; db.Companies.Add(company); db.UserCompanyRefs.Add(userCompanyRef); db.SaveChanges(); return(true); } catch (Exception e) { return(false); throw new Exception("Error: ", e); } }
public ActionResult Create(Company company, UserCompanyRef userCompanyRef, string picture) { if (ModelState.IsValid) { var result = _companiesService.Create(company, userCompanyRef, User.Identity.GetUserId().ToString(), picture); return(RedirectToAction("Index", "UserPanel")); } return(View(company)); }