예제 #1
0
        public IHttpActionResult Post([FromBody] Contracts.Company.CreateCompany create)
        {
            var result = CompanyService.Create(create);

            UploadedImage uploadedImage;

            if (UploadStore.UserImages.TryGetValue(UserId, out uploadedImage) && uploadedImage != null)
            {
                CompanyService.UpdateProfileImage(result.CompanyId, uploadedImage.Image, uploadedImage.ContentType);
                UploadStore.UserImages.TryRemove(UserId, out uploadedImage);
            }

            return(Ok(result));
        }
예제 #2
0
 public static Company ToDataModel(this Contracts.Company.CreateCompany create)
 {
     return(new Company
     {
         Name = create.Name,
         CreatedOn = DateTime.Now,
         UpdatedOn = DateTime.Now,
         DatabaseName = create.Name.Trim().Replace(" ", ""),
         Address1 = create.Address1,
         Address2 = create.Address2,
         Address3 = create.Address3,
         Address4 = create.Address4,
         Phone = create.Phone,
         Email = create.Email,
         OrganizationNumber = create.OrganizationNumber,
         Homepage = create.Homepage,
     });
 }
예제 #3
0
        public Contracts.Company.Company Create(Contracts.Company.CreateCompany create)
        {
            using (var db = new RAAPMasterEntities())
            {
                if (db.Companies.Any(a => a.Name == create.Name))
                {
                    throw new RAAPConflictException("Name is already in use, please try another name.");
                }
                var company = create.ToDataModel();

                using (var sqlConnection = new SqlConnection(db.Database.Connection.ConnectionString))
                {
                    sqlConnection.Open();

                    var sqlCommand = new SqlCommand(string.Format(SqlCreateCompany, company.DatabaseName), sqlConnection);
                    sqlCommand.ExecuteNonQuery();
                }

                db.Companies.Add(company);
                db.SaveChanges();

                return(company.ToContract());
            }
        }