示例#1
0
 private static void DeleteCompany(Company entity)
 {
     try
     {
         ICompanyRepository repository = new CompanyRepository();
         repository.Delete(entity.Id);
     }
     catch (Exception ex)
     {
         throw new DeleteEntityException<Company>();
     }
 }
        public void Create(Company entity)
        {
            using (var context = GetContext())
            {
                var existingEntity = context.Companies.FirstOrDefault(p => p.Name == entity.Name);
                if (existingEntity != null)
                {
                    throw new DuplicateEntityNameException();
                }
                Company soc = new Company()
                {
                    Id = DbIdHelper.GetNextID(),
                    Address = entity.Address,
                    Name = entity.Name,
                    CUI = entity.CUI
                };
                context.Companies.AddObject(soc);

                base.Commit(context);
            }
        }
 public void Edit(Company entity)
 {
     using (var context = GetContext())
     {
         var existingCompany = context.Companies.FirstOrDefault(p => p.Id == entity.Id);
         if (existingCompany == null)
         {
             throw new Exception("invalid company id: " + entity.Id);
         }
         else
         {
             //get companies with the same name but different id
             var existingEntity = context.Companies.FirstOrDefault(p => p.Name == entity.Name && p.Id != entity.Id);
             if (existingEntity != null)
             {
                 throw new DuplicateEntityNameException();
             }
             existingCompany.Address = entity.Address;
             existingCompany.Name = entity.Name;
             existingCompany.CUI = entity.CUI;
             base.Commit(context);
         }
     }
 }
 public void Save(object param)
 {
     try
     {
         if (IsValid())
         {
             //update fields
             if (currentEntity == null || currentEntity.Id == 0)
             {
                 //create
                 currentEntity = new Company();
                 UpdateFields();
                 companyRepository.Create(currentEntity);
             }
             else
             {
                 //edit
                 UpdateFields();
                 companyRepository.Edit(currentEntity);
             }
             WindowHelper.OpenInformationDialog(Messages.InfoWasSaved);
             Mediator.Instance.SendMessage(MediatorActionType.CloseWindow, this.Guid);
             Mediator.Instance.SendMessage(MediatorActionType.RefreshList, this.Guid);
         }
         else
         {
             WindowHelper.OpenErrorDialog("Va rugam completati toate campurile");
         }
     }
     catch (DuplicateEntityNameException dcne)
     {
         WindowHelper.OpenErrorDialog("Exista deja o societate cu acelasi nume!");
     }
     catch (Exception ex)
     {
         Logger.Instance.LogException(ex);
         WindowHelper.OpenErrorDialog(Messages.ErrorSavingInfo);
     }
 }
 public void SetEntityToEdit(object param)
 {
     CompanyViewModel = new CompanyViewModel();
     if (param is Company)
     {
         this.Title = "Editare Societate";
         currentEntity = param as Company;
         CompanyViewModel.Name = currentEntity.Name;
         CompanyViewModel.Cui = currentEntity.CUI;
         CompanyViewModel.Address = currentEntity.Address;
     }
     else
     {
         this.Title = "Creare Societate";
         CompanyViewModel.Name = "";
         CompanyViewModel.Cui = "";
         CompanyViewModel.Address = "";
     }
 }
 /// <summary>
 /// Create a new Company object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="address">Initial value of the Address property.</param>
 /// <param name="cUI">Initial value of the CUI property.</param>
 public static Company CreateCompany(global::System.Int64 id, global::System.String name, global::System.String address, global::System.String cUI)
 {
     Company company = new Company();
     company.Id = id;
     company.Name = name;
     company.Address = address;
     company.CUI = cUI;
     return company;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Companies EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCompanies(Company company)
 {
     base.AddObject("Companies", company);
 }