//Update
        public string update(CustomerRelationshipDto tCustomerRelationshipDto)
        {
            try
            {
                CustomerRelationship tCustomerRelationshipUpdate = _context.CustomerRelationship.Find(tCustomerRelationshipDto.Id);
                if (tCustomerRelationshipUpdate == null)
                {
                    return("1");
                }
                tCustomerRelationshipUpdate.Id   = tCustomerRelationshipDto.Id;
                tCustomerRelationshipUpdate.Name = tCustomerRelationshipDto.Name;

                tCustomerRelationshipUpdate.Status     = tCustomerRelationshipDto.Status;
                tCustomerRelationshipUpdate.CreateDate = tCustomerRelationshipDto.CreateDate;
                tCustomerRelationshipUpdate.CreateUser = tCustomerRelationshipDto.CreateUser;

                _context.CustomerRelationship.Update(tCustomerRelationshipUpdate);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
        public static string GetCustomerRelationship(RestCommand command, int customerRelationshipID)
        {
            CustomerRelationship customerRelationship = CustomerRelationships.GetCustomerRelationship(command.LoginUser, customerRelationshipID);

            if (customerRelationship.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(customerRelationship.GetXml("CustomerRelationship", true));
        }
 public CustomerRelationshipDto get(string id)
 {
     try
     {
         CustomerRelationship bb = _context.CustomerRelationship.Find(id);
         _context.Entry(bb).Collection(b => b.Customer).Load();
         //               _context.Entry(bb).Reference(b => b.Province).Load();
         return(mapper.Map <CustomerRelationship, CustomerRelationshipDto>(bb));
     }
     catch (Exception)
     {
         return(null);
     }
 }
        public string create(CustomerRelationshipDto tCustomerRelationshipDto)
        {
            try
            {
                CustomerRelationship tCustomerRelationshipNew = mapper.Map <CustomerRelationshipDto, CustomerRelationship>(tCustomerRelationshipDto);
                tCustomerRelationshipNew.Id         = Guid.NewGuid().ToString();
                tCustomerRelationshipNew.CreateDate = DateTime.Now;

                _context.CustomerRelationship.Add(tCustomerRelationshipNew);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
        public string delete(string id)
        {
            try
            {
                CustomerRelationship tCustomerRelationshipRemove = _context.CustomerRelationship.Find(id);
                if (tCustomerRelationshipRemove == null)
                {
                    return("1");
                }

                _context.CustomerRelationship.Remove(tCustomerRelationshipRemove);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
        public string lockItem(string id)
        {
            try
            {
                CustomerRelationship tCustomerRelationshipBlock = _context.CustomerRelationship.Find(id);
                if (tCustomerRelationshipBlock == null)
                {
                    return("1");
                }
                tCustomerRelationshipBlock.Status = false;

                _context.CustomerRelationship.Update(tCustomerRelationshipBlock);
                _context.SaveChanges();
                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }