예제 #1
0
 public void CreateOrganizationWithNewAdmin(
     string organizationName,
     string userEmail,
     string password)
 {
     UsingTransaction(organizationName: organizationName, userEmail: userEmail, action: () =>
     {
         var user = userFactory.Create(new Email(userEmail), new Password(password), Role.Admin);
         userRepository.Add(user);                 // Save before organization creation to assign Id;
         var organization = organizationFactory.Create(organizationName, user);
         organizationRepository.Add(organization);
     });
 }
예제 #2
0
        public void CreateSampleOrganizationAndProject(string userId)
        {
            if (_projectRepository.GetByApiKey(SAMPLE_API_KEY) != null)
            {
                return;
            }

            User user         = _userRepository.GetByIdCached(userId);
            var  organization = new Organization {
                Name = "Acme"
            };

            _billingManager.ApplyBillingPlan(organization, BillingManager.UnlimitedPlan, user);
            organization = _organizationRepository.Add(organization);

            var project = new Project {
                Name = "Disintegrating Pistol", TimeZone = TimeZone.CurrentTimeZone.StandardName, OrganizationId = organization.Id
            };

            project.NextSummaryEndOfDayTicks = TimeZoneInfo.ConvertTime(DateTime.Today.AddDays(1), project.DefaultTimeZone()).ToUniversalTime().Ticks;
            project.ApiKeys.Add(SAMPLE_API_KEY);
            project.Configuration.Settings.Add("IncludeConditionalData", "true");
            project.AddDefaultOwnerNotificationSettings(userId);
            project = _projectRepository.Add(project);

            _organizationRepository.IncrementStats(project.OrganizationId, projectCount: 1);

            user.OrganizationIds.Add(organization.Id);
            _userRepository.Update(user);
        }
예제 #3
0
        public void CreateOrganization(CreateOrganizationViewModel orgViewModel)
        {
            Organization organization = new Organization()
            {
                Id   = Guid.NewGuid().ToString(),
                Name = orgViewModel.OrganizationName
            };
            Employee employee = new Employee()
            {
                Id             = Guid.NewGuid().ToString(),
                FirstName      = orgViewModel.CeoFirstName,
                LastName       = orgViewModel.CeoLastName,
                Email          = orgViewModel.Email,
                Password       = orgViewModel.Password,
                DoB            = orgViewModel.DoB,
                OrganizationId = organization.Id
            };

            OrganizationRepository organizationRepository = new OrganizationRepository();
            EmployeeRepository     employeeRepository     = new EmployeeRepository();

            using (TransactionScope transactionScope = new TransactionScope())
            {
                try
                {
                    organizationRepository.Add(organization);
                    employeeRepository.Add(employee);
                    transactionScope.Complete();
                }
                catch
                {
                    throw new Exception("Transaction failed");
                }
            }
        }
예제 #4
0
        public void Add_AddsItemToDbSet()
        {
            var newItem = new Organization()
            {
                OrganizationId = 4,
                Description    = "DD",
                Name           = "TestName"
            };

            var mockSet = new Mock <DbSet <Organization> >().SetupData(new List <Organization>());

            mockSet.Setup(m => m.Add(It.IsAny <Organization>())).Returns(newItem);

            var mockContext = new Mock <CountryContext>();

            mockContext.Setup(c => c.Set <Organization>()).Returns(mockSet.Object);

            var service = new OrganizationRepository(mockContext.Object);

            // Act
            var item = service.Add(newItem);

            mockSet.Verify(m => m.Add(newItem), Times.Once);
            Assert.IsNotNull(item);
            Assert.AreEqual(item.Description, newItem.Description);
            Assert.AreEqual(item.Name, newItem.Name);
        }
예제 #5
0
 public IActionResult Create(Organization org)
 {
     if (ModelState.IsValid)
     {
         organizationRepository.Add(org);
         return(RedirectToAction("Index"));
     }
     return(View(org));
 }
 public bool Add(Organization organization)
 {
     if (organization != null)
     {
         bool isAdded = _organizationRepository.Add(organization);
         return(isAdded);
     }
     return(false);
 }
예제 #7
0
        public OperationResult Save([FromBody] OrganizationItem organization)
        {
            var operationResult = new OperationResult {
                IsSuccess = true
            };

            try
            {
                if (organization.OrganizationId > 0)
                {
                    var existingItem = OrganizationRepository.Find(organization.OrganizationId);
                    organization.Adapt <OrganizationItem, Organization>(existingItem);
                    OrganizationRepository.Update(existingItem);
                    operationResult.SuccessMessage = "Organization Updated Successfully.";
                }
                else
                {
                    var item = organization.Adapt <OrganizationItem, Organization>();
                    OrganizationRepository.Add(item);

                    #region create admin user for this organization

                    var newUser = organization.Adapt <UserItem, User>();
                    newUser.Id             = Guid.NewGuid().ToString();
                    newUser.UserName       = organization.Email;
                    newUser.PhoneNumber    = organization.ContactPhone;
                    newUser.OrganizationId = item.OrganizationId;
                    newUser.IsActive       = true;

                    var result = UserManager.CreateAsync(newUser, organization.Password).Result;
                    if (result.Succeeded)
                    {
                        UserRoleDetail.Add(new UserRoleDetail {
                            RoleId = Convert.ToInt32(Roles.Admin), UserId = newUser.Id, IsActive = true
                        });                                                                                                                    //admin role
                        operationResult.IsSuccess      = true;
                        operationResult.SuccessMessage = "Organization Created Successfully.";
                    }
                    else
                    {
                        OrganizationRepository.Remove(item.OrganizationId);
                        operationResult.IsSuccess    = false;
                        operationResult.ErrorMessage = result.Errors.Select(p => p.Description).FirstOrDefault();
                    }

                    #endregion create admin user for this organization
                }
            }
            catch (Exception ex)
            {
                operationResult.IsSuccess    = false;
                operationResult.ErrorMessage = ex.Message;
            }

            return(operationResult);
        }
예제 #8
0
        //Add Data
        public bool Add(Organization objOrganisetion)
        {
            var isAdded = false;

            isAdded = _organizationRepository.Add(objOrganisetion);
            if (isAdded)
            {
                return(true);
            }
            return(isAdded);
        }
예제 #9
0
 public bool Add(Organization organization)
 {
     if (organization == null)
     {
         return(false);
     }
     if (organization.Code.Length > 3)
     {
         return(false);
     }
     return(repository.Add(organization));
 }
예제 #10
0
 public HttpResponseMessage Add(HttpRequestMessage request, Organization org)
 {
     try
     {
         using (OrganizationRepository repository = new OrganizationRepository())
         {
             repository.Add(org);
             repository.SaveAll();
         }
         return(request.CreateResponse <Organization>(HttpStatusCode.OK, org));
     }
     catch (Exception e)
     {
         return(request.CreateErrorResponse(HttpStatusCode.BadRequest, "Não foi possível inserir usuário [" + e.Message + "]"));
     }
 }
예제 #11
0
        private static void CreateOrgTest()
        {
            var orgRepo = new OrganizationRepository();

            var org = new Organization
            {
                Code      = "TESTING",
                OrgName   = "Testing Company",
                OrgDesc   = "This is a testing company",
                RegdNum   = "REGNO-TEST",
                PAN       = "PAN-TEST",
                TAN       = "TAN-TEST",
                GSTIN     = "GSTIN-TEST",
                IsEnabled = true,
                Address   = new Address
                {
                    Attention    = "Attn Test",
                    AddressLine1 = "Test address line 1",
                    AddressLine2 = "Test address line 2",
                    City         = "Test City",
                    AddressState = "Test State",
                    Country      = "Test Country",
                    PostalCode   = "TEST-PIN",
                    Phone        = "TEST-PHONE",
                    Fax          = "TEST-FAX"
                },
                Contact = new Contact
                {
                    Salutation   = "Mr.",
                    FirstName    = "TestFirst",
                    LastName     = "TestLast",
                    Designation  = "Test Designation",
                    Department   = "Test Department",
                    Email        = "*****@*****.**",
                    WorkPhone    = "TEST-WORK-PHONE",
                    MobileNumber = "TEST-MOBILE-NUMBER"
                }
            };

            //orgRepo.UpdateYear(org);
            orgRepo.Add(org);
        }
예제 #12
0
        protected override void CreateData()
        {
            foreach (Organization organization in OrganizationData.GenerateSampleOrganizations())
            {
                if (organization.Id == TestConstants.OrganizationId3)
                {
                    _billingManager.ApplyBillingPlan(organization, BillingManager.FreePlan, UserData.GenerateSampleUser());
                }
                else
                {
                    _billingManager.ApplyBillingPlan(organization, BillingManager.SmallPlan, UserData.GenerateSampleUser());
                }

                _organizationRepository.Add(organization);
            }

            foreach (Project project in ProjectData.GenerateSampleProjects())
            {
                Organization organization = _organizationRepository.GetById(project.OrganizationId);
                organization.ProjectCount += 1;
                _organizationRepository.Update(organization);

                Repository.Add(project);
            }

            var membershipProvider = new MembershipProvider(_userRepository.Collection);

            foreach (User user in UserData.GenerateSampleUsers())
            {
                if (user.Id == TestConstants.UserId)
                {
                    user.OrganizationIds.Add(TestConstants.OrganizationId2);
                    user.OrganizationIds.Add(TestConstants.OrganizationId3);
                }

                membershipProvider.CreateAccount(user);
            }
        }
예제 #13
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                txtCode_Validated(this, null);
                txtName_Validated(this, null);
                if (!string.IsNullOrEmpty(orgErrors.GetError(txtCode)) ||
                    !string.IsNullOrEmpty(orgErrors.GetError(txtName)))
                {
                    return;
                }

                if (_id == 0)
                {
                    if (_repository.Add(_org) > 0)
                    {
                        //_org = new Organization();
                        //orgBindingSource.DataSource = _org;
                        //yearBindingSource.DataSource = _org.Year;
                        //addressBindingSource.DataSource = _org.Address;
                        //contactBindingSource.DataSource = _org.Contact;
                        //txtCode.Focus();
                        Close();
                    }
                }
                else
                {
                    if (_repository.Update(_id, _org))
                    {
                        Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public ActionResult OrganizationAdd(OrganizationViewModel mod3l)
        {
            Organization oo = new Organization();

            oo.Name        = mod3l.Name;
            oo.Description = mod3l.Description;
            oo.Place       = mod3l.Place;
            oo.Organizer   = _userRep.Find(mod3l.Organizer_Id);
            oo.OrgDate     = mod3l.OrgDate;
            _orgRep.Add(oo);

            oo.ImageUrl = oo.Name + "_" + oo.Id + ".jpg";

            _orgRep.Update(oo);

            string imageway = ConfigurationManager.AppSettings["ImagePath"] + @"\" + oo.ImageUrl;

            Request.Files[0].SaveAs(imageway);



            return(RedirectToAction("OrganizationList"));
        }
예제 #15
0
        public bool Add(Organization organization)
        {
            using (var ts = new TransactionScope())
            {
                if (organization == null)
                {
                    return(false);
                }

                if (organization.Code.Length != 3)
                {
                    return(false);
                }

                bool isSaveed = repository.Add(organization);

                ts.Complete();



                return(isSaveed);
            }
        }
예제 #16
0
        public ActionResult OrganizasyonAdd(OrganizationModelview entity)
        {
            Organization org = new Organization();

            org.Name        = entity.Name;
            org.Description = entity.Description;
            org.OrgDate     = entity.OrgDate;
            org.Place       = entity.Place;
            org.Organizer   = _userrep.Find(entity.Organizer_Id);

            _Orgrep.Add(org);

            org.ImageUrl = org.Name + "_" + org.Id + ".jpg";

            _Orgrep.Update(org);

            string imageway = ConfigurationManager.AppSettings["ImagePath"] + "/" + org.ImageUrl;

            Request.Files[0].SaveAs(imageway);


            return(RedirectToAction("Organizasyonlar"));
        }
예제 #17
0
        public ActionResult AddOrganization(Organization entity)
        {
            if (Request.Files.Count <= 0)
            {
                ModelState.AddModelError("ImageValidation", "Image seçilmedi");
            }
            if (Request.Files[0].ContentLength <= 0)
            {
                ModelState.AddModelError("ImageValidation", "Image seçilmedir");
            }


            if (!ModelState.IsValid)
            {
                return(View(entity));
            }



            Image image = new Image();

            image.ImageUrl = Request.Files[0].FileName;
            imagerep.Add(image);

            var imagePath = ConfigurationManager.AppSettings["ImagePath"] + "/" + image.Id + "_" + image.ImageUrl;

            Request.Files[0].SaveAs(imagePath);

            entity.ImageId = image.Id;


            orgrep.Add(entity);


            return(RedirectToAction("ListOrgs"));
        }
 public bool Add(Organization organization)
 {
     return(_organizationRepository.Add(organization));
 }
예제 #19
0
        public bool Add(Organization organization)
        {
            bool IsSave = _organizationRepository.Add(organization);

            return(IsSave);
        }
 public Organization CreateOrganization(Organization organization, string ownerEmail)
 {
     return(repository.Add(organization, ownerEmail));
 }
예제 #21
0
        public ActionResult Add(ProjectModel model)
        {
            ViewBag.Organizations    = Organizations;
            ViewBag.HasOrganizations = Organizations.Any();
            ViewBag.TimeZones        = TimeZoneInfo.GetSystemTimeZones();

            #region Validation

            Organization organization = null;

            if (!String.IsNullOrEmpty(model.OrganizationName))
            {
                Organization existing = Organizations.FirstOrDefault(o => o.Name == model.OrganizationName);
                organization = existing ?? new Organization {
                    Name = model.OrganizationName.Trim()
                };
            }
            else if (!String.IsNullOrEmpty(model.OrganizationId))
            {
                organization = Organizations.FirstOrDefault(o => o.Id == model.OrganizationId);
                ModelState state = ModelState["OrganizationName"];
                if (state != null)
                {
                    state.Errors.Clear();
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (organization == null)
            {
                ModelState.AddModelError("OrganizationName", "Organization Name is required.");
                return(View(model));
            }

            if (!String.IsNullOrEmpty(organization.Id) && Projects.Count(p => p.OrganizationId == organization.Id && String.Equals(p.Name, model.Name, StringComparison.OrdinalIgnoreCase)) > 0)
            {
                ModelState.AddModelError("Name", "A project with this name already exists.");
                return(View(model));
            }

            #endregion

            if (String.IsNullOrEmpty(organization.Id))
            {
                if (!_billingManager.CanAddOrganization(User.UserEntity))
                {
                    ModelState.AddModelError(String.Empty, "Please upgrade your plan to add an additional organization.");
                    return(View(model));
                }

                _billingManager.ApplyBillingPlan(organization, Settings.Current.EnableBilling ? BillingManager.FreePlan : BillingManager.UnlimitedPlan, User.UserEntity);
                organization = _organizationRepository.Add(organization);
                _notificationSender.OrganizationUpdated(organization.Id);

                User user = _userRepository.GetById(User.UserEntity.Id);
                user.OrganizationIds.Add(organization.Id);
                _userRepository.Update(user);
            }

            var project = new Project {
                Name = model.Name, TimeZone = model.TimeZone, OrganizationId = organization.Id
            };
            project.NextSummaryEndOfDayTicks = TimeZoneInfo.ConvertTime(DateTime.Today.AddDays(1), project.DefaultTimeZone()).ToUniversalTime().Ticks;
            project.ApiKeys.Add(Guid.NewGuid().ToString("N").ToLower());
            project.AddDefaultOwnerNotificationSettings(User.UserEntity.Id);

            if (!_billingManager.CanAddProject(project))
            {
                ModelState.AddModelError(String.Empty, "Please upgrade your plan to add an additional project.");
                return(View(model));
            }

            project = _projectRepository.Add(project);

            _organizationRepository.IncrementStats(project.OrganizationId, projectCount: 1);
            _notificationSender.ProjectUpdated(organization.Id, project.Id);

            return(RedirectToAction("Configure", "Project", new { id = project.Id }));
        }