Пример #1
0
        /// <summary>
        /// Updates the material.
        /// </summary>
        /// <param name="material">The material which will be updated.</param>
        public void CreateOrUpdateMaterial(MaterialPrimitive materialPrimitive)
        {
            try
              {
            using (SmartWorkingEntities context = new SmartWorkingEntities())
            {
              Material material = materialPrimitive.GetEntity();

              Material existingObject = context.Materials.Where(x => x.Id == material.Id).FirstOrDefault();

              //no record of this item in the DB, item being passed in has a PK
              if (existingObject == null && material.Id > 0)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(new Exception("Błąd zapisu do bazy")),
                                                        "Obiekt nie istniał w bazie, a jego Id jest większe od 0.");
              }
              //Item has no PK value, must be new
              else if (material.Id <= 0)
              {
            context.Materials.AddObject(material);
              }
              //Item was retrieved, and the item passed has a valid ID, do an update
              else
              {
            context.Materials.ApplyCurrentValues(material);
              }

              context.SaveChanges();
            }
              }
              catch (Exception e)
              {
            throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
              }
        }
Пример #2
0
 /// <summary>
 /// Deletes the material.
 /// </summary>
 /// <param name="material">The material which will be deleted.</param>
 public void DeleteMaterial(MaterialPrimitive materialPrimitive)
 {
     try
       {
     using (var context = new SmartWorkingEntities())
     {
       Material material = context.Materials.Where(x => x.Id == materialPrimitive.Id).FirstOrDefault();
       if (material != null)
       {
     material.Deleted = DateTime.Now;
     context.SaveChanges();
       }
       else
       {
     throw new Exception("This car does not exist in db.");
       }
     }
       }
       catch (Exception e)
       {
     throw new FaultException<ExceptionDetail>(new ExceptionDetail(e), e.Message);
       }
 }
Пример #3
0
        public static MaterialPrimitive GetPrimitive(this Material entity)
        {
            MaterialPrimitive primitive = new MaterialPrimitive();

                primitive.Id = entity.Id;

                primitive.Name = entity.Name;

                primitive.Producer_Id = entity.Producer_Id;

                primitive.Deliverer_Id = entity.Deliverer_Id;

                primitive.InternalName = entity.InternalName;

                primitive.Deleted = entity.Deleted;

                primitive.Deactivated = entity.Deactivated;

                primitive.MaterialType = entity.MaterialType;

                return primitive;
        }
Пример #4
0
        public static MaterialPrimitive GetPrimitiveCopy(this MaterialPrimitive primitiveToCopy)
        {
            if (primitiveToCopy == null) return null;

                MaterialPrimitive primitive = new MaterialPrimitive();

                primitive.Id = primitiveToCopy.Id;

                primitive.Name = primitiveToCopy.Name;

                primitive.Producer_Id = primitiveToCopy.Producer_Id;

                primitive.Deliverer_Id = primitiveToCopy.Deliverer_Id;

                primitive.InternalName = primitiveToCopy.InternalName;

                primitive.Deleted = primitiveToCopy.Deleted;

                primitive.Deactivated = primitiveToCopy.Deactivated;

                primitive.MaterialType = primitiveToCopy.MaterialType;

                return primitive;
        }