Exemplo n.º 1
0
        public Guid Add(Customer entity)
        {
            if (string.IsNullOrEmpty(entity.SSN))
                throw new ArgumentException("Customer number cannot be empty!");

            if (string.IsNullOrEmpty(entity.ContactDetail.ContactName))
                throw new ArgumentException("Customer name cannot be empty!");

            using (OpenPOSDbEntities ctx = new OpenPOSDbEntities())
            {
                if (CheckDuplicate(entity.Id, entity.SSN, ctx))
                {
                    throw new ArgumentException("Duplicate Customer number found!");
                }

                try
                {
                    ctx.Customers.AddObject(entity);
                    ctx.SaveChanges();
                    return entity.Id;
                }
                catch (Exception ex)
                {
                    LogService.Error("Error while adding customer", ex);
                    throw new ArgumentException("Error while adding new customer!");
                }
            }
        }
Exemplo n.º 2
0
        public void Update(Customer entity)
        {
            if (entity.Id.Equals(Guid.Empty))
                throw new ArgumentException("Customer Id cannot be empty!");

            if (string.IsNullOrEmpty(entity.SSN))
                throw new ArgumentException("Customer number cannot be empty!");

            if (string.IsNullOrEmpty(entity.ContactDetail.ContactName))
                throw new ArgumentException("Customer name cannot be empty!");

            using (OpenPOSDbEntities ctx = new OpenPOSDbEntities())
            {
                if (CheckDuplicate(entity.Id, entity.SSN, ctx))
                {
                    throw new ArgumentException("Duplicate Customer number found!");
                }

                try
                {

                    ctx.Customers.Attach(entity);
                    ctx.ContactDetails.Attach(entity.ContactDetail);

                    ctx.ObjectStateManager.ChangeObjectState(entity, System.Data.EntityState.Modified);
                    ctx.ObjectStateManager.ChangeObjectState(entity.ContactDetail, System.Data.EntityState.Modified);

                    ctx.Customers.ApplyCurrentValues(entity);
                    ctx.ContactDetails.ApplyCurrentValues(entity.ContactDetail);

                    ctx.SaveChanges();

                }
                catch (Exception ex)
                {
                    LogService.Error("Error while updating customer", ex);
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Create a new Customer object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="sSN">Initial value of the SSN property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 /// <param name="contactDetailId">Initial value of the ContactDetailId property.</param>
 /// <param name="createdBy">Initial value of the CreatedBy property.</param>
 /// <param name="createdOn">Initial value of the CreatedOn property.</param>
 public static Customer CreateCustomer(global::System.Guid id, global::System.String sSN, global::System.Boolean status, global::System.Guid contactDetailId, global::System.String createdBy, global::System.DateTime createdOn)
 {
     Customer customer = new Customer();
     customer.Id = id;
     customer.SSN = sSN;
     customer.Status = status;
     customer.ContactDetailId = contactDetailId;
     customer.CreatedBy = createdBy;
     customer.CreatedOn = createdOn;
     return customer;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomers(Customer customer)
 {
     base.AddObject("Customers", customer);
 }