Ejemplo n.º 1
0
        public CoWorker AddCoWorker(CoWorker coWorker)
        {
            CoWorker retVal = null;
            using (var db = new CoWorkerDbContext())
            {
                //validate if record exists.
                if (db.CoWorkers.Any(c => c.Name == coWorker.Name))
                {
                    throw new FaultException(string.Format("CoWorker with Name of {0} already exists.", coWorker.Name));
                }

                try
                {
                    db.CoWorkers.Add(coWorker);
                    db.SaveChanges();

                    long id = coWorker.CoWorkerId;

                    if (id > 0)
                    {
                        var result = db.CoWorkers.Find(new object[] { id });
                        retVal = result as CoWorker;
                    }
                    else
                    {
                        throw new FaultException("Coworker was not saved.");
                    }
                }
                catch (Exception e)
                {
                }
            }

            return retVal;
        }
Ejemplo n.º 2
0
        public CoWorker AddCoWorker(CoWorker coWorker)
        {
            CoWorker retVal = null;
            //using (var db = new CoWorkerDbContext())
            //{
            //    try
            //    {
            //        db.CoWorkers.Add(coWorker);
            //        db.SaveChanges();

            //        long id = coWorker.CoWorkerId;

            //        if (id > 0)
            //        {
            //            var result = db.CoWorkers.Find(new object[] { id, coWorker.Name });
            //            retVal = result as CoWorker;
            //        }
            //        else
            //        {
            //            throw new Exception("Coworker was not saved.");
            //        }
            //    }
            //    catch (Exception e)
            //    {
            //    }
            //}

            return coWorker;
        }
Ejemplo n.º 3
0
 public CoWorker UpdateCoWorker(CoWorker coWorker)
 {
     throw new NotImplementedException();
 }