/// <summary>
 /// Update Client
 /// </summary>
 /// <returns></returns>
 public Tuple <bool, string> Update()
 {
     try
     {
         using (Easycase.DataModel.EasyCaseDBEntities DB = new DataModel.EasyCaseDBEntities())
         {
             var client = new DataModel.Client
             {
                 FirstName       = this.FirstName,
                 Citizenship     = this.Citizenship,
                 Country         = this.Country,
                 DOB             = this.DOB,
                 Email           = this.Email,
                 ImageId         = this.ImageId,
                 LastName        = this.LastName,
                 MartialStatusId = this.MartialStatusId,
                 Notes           = this.Notes,
                 PhoneNo         = this.PhoneNo,
                 Prefix          = this.Prefix,
                 PurposeId       = this.PurposeId,
                 ID        = this.ID,
                 Deleted   = false,
                 CreatedBy = this.CreatedBy
             };
             DB.Entry(client).State = System.Data.Entity.EntityState.Modified;
             DB.SaveChanges();
         }
         return(new Tuple <bool, string>(true, Messages.SUCCESS));
     }
     catch (Exception ex)
     {
         Logs.SaveLog(ex.Message);
         return(new Tuple <bool, string>(false, ex.Message));
     }
 }
Exemple #2
0
 public Clients()
 {
     if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
     {
         ClientList    = new ObservableCollection <DataModel.Client>(DataModel.Client.LoadAll());
         CurrentClient = new DataModel.Client();
         SaveAsNew     = true;
         Refresh();
     }
 }
Exemple #3
0
        public void SaveCurrentClient()
        {
            DataModel.Client matchByCode = ClientList.FirstOrDefault(client => client.IdCode == CurrentClient.IdCode);

            // An IdCode collision occurred and it's not the same client.
            if (matchByCode != null && matchByCode.Id != CurrentClient.Id)
            {
                throw new Exception($"Asiakas tunnisteella {CurrentClient.IdCode} on jo olemassa.");
            }
            if (SaveAsNew && matchByCode == null)
            {
                CurrentClient.Id = null;
            }

            CurrentClient.Save();
            ClientList = new ObservableCollection <DataModel.Client>(DataModel.Client.LoadAll());

            // If the user changes the IdCode and saves the client as new, this updates the Id to the view model.
            CurrentClient = ClientList.First(client => client.IdCode == CurrentClient.IdCode).Copy();
        }
 /// <summary>
 /// Save data in database
 /// </summary>
 /// <returns></returns>
 public Tuple <bool, string, long> Save()
 {
     try
     {
         long id = 0;
         using (Easycase.DataModel.EasyCaseDBEntities DB = new DataModel.EasyCaseDBEntities())
         {
             var client = new DataModel.Client
             {
                 FirstName       = this.FirstName,
                 Citizenship     = this.Citizenship,
                 Country         = this.Country,
                 DOB             = this.DOB,
                 Email           = this.Email,
                 ImageId         = this.ImageId,
                 LastName        = this.LastName,
                 MartialStatusId = this.MartialStatusId,
                 Notes           = this.Notes,
                 PhoneNo         = this.PhoneNo,
                 Prefix          = this.Prefix,
                 PurposeId       = this.PurposeId,
                 Deleted         = false,
                 CreatedBy       = this.CreatedBy
             };
             DB.Clients.Add(client);
             DB.SaveChanges();
             id = client.ID;
         }
         return(new Tuple <bool, string, long>(true, Messages.SUCCESS, id));
     }
     catch (Exception ex)
     {
         Logs.SaveLog(ex.Message);
         return(new Tuple <bool, string, long>(false, ex.Message, 0));
     }
 }
 public Client()
 {
     _client = new DataModel.Client();
 }
Exemple #6
0
 public static bool CanSaveForClient(DataModel.Client client)
 {
     return(DataModel.Client.Exists(client.Id));
 }
Exemple #7
0
 public static bool CanRemoveClient(DataModel.Client client)
 {
     return(DataModel.Task.LoadAllFor(client).Count() == 0);
 }
Exemple #8
0
 public void RemoveClient(DataModel.Client client)
 {
     client.Delete();
     ClientList.Remove(client);
 }
Exemple #9
0
 public void Reset()
 {
     ClientList    = new ObservableCollection <DataModel.Client>(DataModel.Client.LoadAll());
     CurrentClient = new DataModel.Client();
     Refresh();
 }